This article is a mirror article of machine translation, please click here to jump to the original article.

View: 8132|Reply: 0

XML Beginner Syntax

[Copy link]
Posted on 2/9/2015 1:24:43 PM | | |

XML documents use self-descriptive and simple syntax.
<?xml version="1.0" encoding="ISO-8859-1"?>   
<note>   
<to>Tove</to>   
<from>Jani</from>   
<heading>Reminder</heading>   
<body>Don’t forget me this weekend!</body>   
</note>
Line 1 of the document: XML declaration - Defines the version of the XML standard that this document follows, in this case version 1.0 of the standard, using the ISO-8859-1 (Latin-1/West European) character set.
The next line describes the root element of the document (like it was saying: "this document is a note"):  
Line 2 of the document is the root element (as if to say "this document is a note"):
<note>Lines 3-6 of the document describe the four subnodes (to, from, heading, and body) of the root element: <to>Tove</to><from>Jani</from><heading>Reminder</heading><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 a note from Ordm to Lin? Can you not acknowledge XML as a beautiful self-descriptive language?
All XML documents must have an end mark
In XML documents, ignoring the end tag is not compliant.
In HTML documents, some elements can be without closing tags. The following code is perfectly legal in HTML:
<p>This is a paragraph   
<p>This is another paragraph
However, the XML document must have an end tag, as in the following example:
<p>This is a paragraph</p>   
<p>This is another paragraph</p>  
Note: As you may have noticed, the first line in the example above does not have an end mark. This is not a mistake. Because XML declarations are not part of an XML document, they are not XML elements, so there should be no end tags.
XML markup is case-sensitive
Unlike HTML, XML markup is case-sensitive.
In XML, tags <Letter>and tags <letter>are two different markups.
Therefore, the case of the start and end tags must be consistent in the XML document.
<Message>This is incorrect</message>   

<message>This is correct</message>
All XML elements must be reasonably included
  
Incorrect nested inclusions are not allowed in XML.
In HTML, some incorrect inclusions are allowed, such as the following code that can be parsed by the browser:
<b><i>This text is bold and italic</b></i>
In XML, all elements must be nested correctly, and the above code should be written like 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 markup to define, and all other elements must be nested in pairs in the root element. An XML document has and can only have one root element.
All elements can have child elements, and the child elements must be nested correctly in the parent element, and the following code can be illustrated vividly:
<root>   
  <child>   
    <subchild>.....</subchild>   
  </child>   
</root>

Attribute values must be in quotation marks ""
In XML, it is not regulated that an element's attribute value is not quoted in quotation marks.
Just like HTML, XML elements can also have attributes. The properties of XML elements appear in pairs with names/values. The XML syntax specification requires that XML element attribute values must be quoted in quotation marks. Look at the following two examples, the first 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>
The error in the first document is that the attribute values are not led in quotation marks.
The correct way to write it is: date="12/11/99". Incorrect spelling: date=12/11/99.
With XML, whitespace will be preserved   
In XML documents, blank parts are not automatically removed by the parser.

This is different from HTML. In HTML, a sentence like this:
"Hello my name is Ordm" will be displayed as: "Hello my name is Ordm",
Because the HTML parser will automatically remove the blank part of the sentence.
Using XML, CR/LF is converted to LF
With XML, new lines are always identified as LF (Line Feed).
Do you know what a typewriter is? Hehe, a typewriter is a type of machine that was used in the last century to type exclusively. ^&^
When you're done typing a line with your typewriter, you usually have to move the typewriter to the left end of the paper again.
In Windows applications, new lines in text are usually identified as CR LF (carriage return, line feed, car return, line break). In Unix applications, new lines are usually identified as LF. There are also applications that only use CR to represent a new line.
Comments in XML
The syntax for annotations in XML is basically the same as in HTML.
<!-- This is a comment -->  
<!-- This is a comment -- >
XML is nothing special
There really is nothing special about XML. He is just some plain text that is expanded together in angle brackets. Software that edits plain text can also edit XML documents. However, in an XML-enabled application, XML markup often corresponds to special operations, some of which may be visible and others that may not be displayed without any special operations.




Previous:The identification column in the table 'Area' can only be used if a list of columns is used and IDENTITY_INSERT is ON
Next:SQL Server 2000 creates 1024 tables in a loop
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com