Learn the syntax rules of XML in web making

Source: Internet
Author: User
Tags date character set end version
xml| Web page | grammar

The syntax rules for XML are simple and rigorous, and are easy to learn and use. Because of this, it is also relatively easy to write software that reads and operates XML.

An example of an XML document

   XML documents use self-describing and simple syntax.

<?xml version= "1.0" encoding= "iso-8859-1"?>  <note>  <to>Tove</to>  <from >Jani</from>  

Line 1th of the document: XML declaration--defines the version of the XML standard that this document follows, in this case the standard for version 1.0, using the Iso-8859-1 (latin-1/west European) character set.

The next line describes the ' document ' of the ' root ' (like it was saying: ' This document be a note '):
The 2nd line of the document is the root element (it's like saying "This document is a note"):

<note>
The first 3--6 line of the document describes the four subnodes of the root element (to, from, heading, and body):
<to>Tove</to>
<from>Jani</from>
<body>don ' t forget me this weekend!</body>
The last line of the document is the end of the root element
</note>

Can you tell from this document that this is ORDM's note to Lin? Can you not accept that XML is a beautiful self-describing language?

All XML documents must have an end tag

   In an XML document, ignoring the end tag is not a rule.

In an HTML document, some elements can have no end tag. The following code is completely legal in HTML:

<p>this is a paragraph  <p>this is another paragraph

However , there must be an end tag in an XML document, as in the following example:

<p>this is a paragraph</p>  <p>this is another paragraph</p>

   Note : You may have noticed that the first line in the example above does not have an end tag. This is not a mistake. Because an XML declaration is not part of an XML document, he is not an XML element and should not have an end tag.

XML markup is case sensitive

   This is not the same as HTML, where XML tags are case sensitive.

In XML, tag <Letter> and tag <letter> are two different tags.

Therefore, the capitalization of the start and end tags in an XML document must be consistent.

<message>this is incorrect</message>  <message>this is correct</message>

All XML elements must reasonably contain the

   

   Incorrect nesting inclusions are not allowed in XML.

In HTML, some incorrect inclusions are allowed, for example, the following code can be parsed by the browser:

<b><i>this text is bold and italic</b></i>

All elements in the XML must be nested properly, and the above code should write this:

<b><i>this text is bold and italic</i></b>

All XML documents must have a root element

   The first element in an XML document is the root element.

All XML documents must contain a separate tag to define, and all other elements must be pair-nested within the root element. An XML document has and can only have one root element.

All elements can have child elements, and child elements must be properly nested within the parent element, and the following code can be described as an image:

<root>    <child>      <subchild>.....</subchild>    </child>  

Property value must use quotation marks ""

   In XML, the attribute value of an element is not set in quotation marks.

Like HTML, XML elements can also have attributes. The attribute of an XML element appears as a pair of name/value. The XML syntax specification requires that XML element attribute values be quoted. Take a look at the following two examples, the first one is wrong and the second is correct.

<?xml version= "1.0" encoding= "iso-8859-1"?> <note date=12/11/2002>  <to>Tove</to>  <from>Jani</from>  </note>

<?xml version= "1.0" encoding= "iso-8859-1"?> <note date=  "12/11/2002" >  <to>tove</to >  <from>Jani</from>  </note>

The error in the first document is that the property value is not quoted in quotation marks.

The correct formulation is: date= "12/11/99". Incorrect wording: date=12/11/99.

Using XML, whitespace will be preserved

   In an XML document, whitespace is not automatically deleted by the parser.

   
This is different from HTML. In HTML, such a sentence:

"Hello my name is ORDM" will be displayed as: "Hello my name is ORDM",

Because the HTML parser automatically removes the blanks from the sentence.

Using XML, CR/LF is converted to LF

   with XML, new lines are always identified as LF(line feeds, wrapping).

Do you know what a typewriter is? Well, typewriters are a type of machine used in the last century. ^&^

When you have finished typing a line, you usually have to move the type head to the left side of the paper.

In Windows applications, new lines in the text are usually identified as CR LF (carriage return, line feed, enter, linefeed). In UNIX applications, new rows are usually identified as LF. There are also applications that use CR only to represent a new row.

Annotations in XML

The syntax for annotations in XML is essentially the same as in HTML.

<!--This is a comment-->
<!--This is a note-->

There's nothing special about XML.

XML does not have a particular place. He's just some plain plain text that's been extended with angle brackets. Software that edits plain text can also edit XML documents. In an XML-enabled application, however, XML tags often correspond to special operations, some of which may be visible, while others may not appear, and there is no special action.



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.