Introduction to J2EE&tdt&XML

Table of contents

One.XML

What is well-formed XML

The role of XML

standard XML format 

2. Element definition

2.1 Add DTD declaration to XML   

2.2 Classification of elements

2.3 Restrictions on elements

3. Attribute definition

grammar

attribute type type

attribute description

tdt parsing            

Four. The difference between XML and JSON

5. Mind map


One.XML

What is well-formed XML

       Well-formed XML is an XML document that follows all the " Rules for XML Documents "

The role of XML

        ①Data interaction

        ② Make configuration

standard XML format 

  • has one and only one element
  • XML tag case is correctly distinguished
  • Use closing tags correctly
  • Nest tags correctly
  • A valid tag name is used
  • define valid properties        

2. Element definition

2.1 Add DTD declaration to XML   

        <!DOCTYPE root[]>

2.2 Classification of elements

        <ELEMENT element-name EMPTY>//empty element

         <ELEMENT element-name (#PCDATA)>//text element

         <ELEMENT element-name (e1,e2)>//mixed element

2.3 Restrictions on elements

        and (,) not (|)

        Times: ①0 or 1:?

                    ②0~N:*

                    ③1~N:+

3. Attribute definition

grammar

        <!ATTLIST element-name att_name type desc>

attribute type type

  •   ID
  • CDATA
  • IDREF
  • reference    

attribute description

  1.   #REQUIRED: required
  2.   #IMPLIED: optional
  3.   Default value Note: only when the type is (male|female) type, desc can use the default value

For example:

<?xml version="1.0" encoding="UTF-8"?>
    <!--
        config tag: can contain 0~N action tags
    -->

tdt解析
<!DOCTYPE config[
    <!ELEMENT config (action+)>
    <!ELEMENT action (forward*)
    <!ATTLIST action 
            path CDATA #REQUIRED
            type CDATA #REQUIRED
    >    
    <!ATTLIST forward 
        name CDATA #REQUIRED
        path CDATA #REQUIRED
        redirect (true|false) 'false'
    
    >


]>
<config>
    <!--
        action tag: can contain 0~N forward tags path: a string starting with /, and the value must be unique and non-empty, the path corresponding to the sub-controller type: string, non-empty, the full class name of the sub-controller --> <action path="/registerAction" type="test.action.RegisterAction"> <forward name="success" path="/index.jsp" redirect="true" /> <forward name="forward name="success" path="/index.jsp" redirect="true" /> ="failed" path="/register.jsp" redirect="false" /> </action> <action path="/loginAction" type="test.action.LoginAction"> <forward name="
        a
    "
    path
        =
        "
    /
    index
        .jsp" redirect="false" />
        <forward name="b" path="/welcome.jsp" redirect="true" />
    </action>
</config>

Four. The difference between XML and JSON


Both XML and JSON are markup languages ​​for data exchange, and they have some differences in syntax and usage:

Syntax structure : XML uses tags while JSON uses brackets.
Data types : XML supports custom data types, while JSON only supports string, number, boolean, array, and object data types.
Readability : XML is easier for humans to read and understand than JSON.
Processing efficiency : JSON is lighter and faster than XML, because JSON does not need redundant tags to describe data like XML.
In general, XML is suitable for complex data structures while JSON is suitable for simple and lightweight data exchange.

5. Mind map

 

Guess you like

Origin blog.csdn.net/qq_73126462/article/details/131666632