Crazy XML learning notes (2) ----------- format requirements

Source: Internet
Author: User
Tags processing instruction
Obviously, you will immediately understand that the most common tool for creating XML files is like HTML, that is, & quot; notepad & quot.

Basic rules of Xml elements

An element is the basic unit of an xml document. an xml document is composed of nested elements. The entire xml document starts from the root element. the root element contains several child elements, and each child element can contain several child elements to form an xml document.

Xml tag syntax:

1. Xml labels are divided into two types:

Single tag: <中国 />

Double flag: <中国>

2. xml tag requirements:

1. the tag name can contain letters (including non-Western European characters), numbers, underscores (_), hyphens (-), colons (:), and periods (.) it cannot start with a number, hyphen, or dot.

2. the tag name cannot contain symbols such as <,>, and $.

3. do not use an English colon (:) unless you are using a namespace.

4. the tag name cannot start with any combination of uppercase and lowercase letters, such as xml and XML.

5. the tag name cannot contain spaces.

6. label names are case sensitive

3. xml tag nesting sub-elements: xml allows deep nesting of sub-elements, as long as reasonable nesting between elements is ensured. in addition, xml elements can be nested with multiple sub-elements with duplicate names. these sub-elements are ordered between them.

First: xml

<中国>

<北京>

<海淀 />

<朝阳>

<朝阳>

Second xml:

<中国>

<北京>

<朝阳>

<朝阳>

<海淀 />

4. empty element: the empty element cannot accept child elements or string content.

Third xml:

Redarmy

: Note: empty elements but attributes are acceptable and multiple attributes are acceptable.

Redarmy

: Note that it includes a space, a space, and a character.

For example, an empty element accepts attributes:

5. character data

Struts2 development details

Struts2 development details

For all spaces and line breaks in XML tags, the XML parser processes them as tag content.

If a text character contains special characters, such <和&由于这些字符都有特殊的含义,因此直接在xml文档中使用该字符串将引起文档的混乱。< strong>

<表达式>

<比较符> 1 + 3 <6

It indicates that the text string contains special characters.

There are two solutions:

1. object reference: replace these special symbols with another special symbol

2,Mark with CDATA: define the entire document as a string.

1. object reference

<表达式>

<比较符> 1 + 3 & <6

The Red <产生了干扰< p>

The solution is as follows:

<表达式>

<比较符> 1 + 3 <6

2. mark with CDATA

All special characters and even valid elements under the special Mark CDATA will be treated as simple strings. Entity reference also becomes useless and becomes a direct text.

The CDATA syntax format is as follows:

文本内容

<表达式>

<比较符>

</p><p> 1+3<6</p><p>

Note: Because the xml document does not parse the content marked with CDATA at all, you can place any content in CDATA without any errors.

1. Notes

The Xml document can also contain character data for interpretation. the strings used for interpretation are not processed by the xml parser. The text used for these interpretations is called comments. Xml document comments are exactly the same as html.

The syntax format of Xml annotations is as follows:

Xml annotations can contain elements and labels.

Note:

1. Xml annotations cannot be placed in tags.

2. do not place the xml document before the xml document Declaration. the declaration of the xml document will always be in the first line.

3. do not use double hyphens (--) in comments (--)

.....

2. processing commands

Processing Command (PI ). The processing command is used to direct the parsing engine to parse the XML document content.

The processing command is used to provide information to the application that processes the xml document, telling the handler how to process the document. A complete xml document processing program can read the processing instructions of the xml document, process the instructions accordingly, or pass it to the next program.

The Xml processing instruction format is as follows:

3. attributes

Xml attributes:

1. attributes of xml elements must have attribute values, which must be enclosed by quotation marks.

2. the same xml element cannot have multiple attributes with the same name.

3. there is no sequence between multiple attributes in the Xml element.


       
   
    
123456780
        
   
    
Java handouts
         
   
    
99
   
  


For example, this book has the attribute isbn book_name price.

So


  


Xml must have a root element.

Overall structure of Xml documents

1. there must be one root element (and only one)

2. elements must end properly.

3. reasonably nested elements

4. Element attributes must have attribute values.

As long as the above conditions are not met, it is a poorly formatted xml document.

As long as the above conditions are met, it is a well-formatted xml document.

Compliance with the dtd or schema is a valid xml document.

An Xml Document is a standard Structured Document that can be converted into a DOM (Document Object Model) tree. its root node corresponds to the root node of the DOM tree.


      
          
    
     
Online Introduction
    Redarmy    
       
           
    
     
Online Introduction
    Redarmy    
   
  




Book


Computer


Computer


.........


Computer


Name


Author

Note:

The root tag must be unique.

Start and end tags must be paired

The tag cannot be staggered.

Empty tag can be written as" <标记名 />"Form

Tags are case sensitive.

The above is the content required by the crazy XML learning notes (2) ------------- format. For more information, see The PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.