Translation

The oldest posts, are written in Italian. If you are interested and you want read the post in English, please use Google Translator. You can find it on the right side. If the translation is wrong, please email me: I'll try to translate for you.

lunedì, agosto 28, 2017

Using XML 02: Introduction, Part 2/3

In the previous post, I introduced an XML file, in its more simple form. Here I would like to be a little more formal. As usual, check the References section to read the sources for more information.

Consider following XML document (I took the information in [1] and [2])


XML Tree Structure

How wrote in [3], a general structure of an XML document is

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


The terms parent, child, and sibling are used to describe the relationships between elements. Parent have children. Children have parents. Siblings are children on the same level (brothers and sisters). All elements can have text content (Death Times Three) and attributes (category="Nero Wolfe").

Self-Describing Syntax

XML uses a much self-describing syntax.

A prolog defines the XML version and the character encoding:

<?xml version="1.0" encoding="UTF-8"?&gt;

The next line is the root element of the document:

<bibliography>

The next line starts a <book> element:

<book category="Nero Wolfe">

The <book> elements have 3 child elements: <title>, <publisher>, <year>.

<Title lang="en">Death Times Three</Title>
<Publisher>Bantam Books</Publisher>
<year month="December">1985</year>

The next line ends the book element:

</book>


XML Syntax Rules [5]

The syntax rules of XML are very simple and logical. The rules are easy to learn and easy to use. If an XML document conforms to the syntax rules below, then it said to be "Well Formed".


XML Documents Must Have a Root Element

<bibliography>
 <book category="Nero Wolfe">

  <Title lang="en">Death Times Threegt;/Title>
  <Publisher>Bantam Books>/Publisher>
  <year month="December">1985>/year>
 </book>
<bibliography>


The XML Prolog

The XML prolog is optional. If it exists, it must come first in the document: 

<?xml version="1.0" encoding="UTF-8"?>


All XML Elements Must Have a Closing Tag

<bibliography>
 <book category="Nero Wolfe">
  <Title lang="en">Death Times Three</Title>
  <Publisher>Bantam Books</Publisher>
  <year month="December">1985</year>
 </book>
</bibliography>


XML Tags are Case Sensitive

<bibliography>
 <book category="Nero Wolfe">
  <Title lang="en">Death Times Three</Title>
  <Publisher>Bantam Books</Publisher>
  <year month="December">1985</year>
 </book>
</bibliography>


XML Elements Must be Properly Nested


<bibliography>
 <book category="Nero Wolfe">
  <Title lang="en">Death Times Three</Title>
  <Publisher>Bantam Books</Publisher>
  <year month="December">1985</year>
 </book>
</bibliography>


XML Attribute Values Must be Quoted

<bibliography>
 <book category="Nero Wolfe">
  <Title lang="en">Death Times Three</Title>
  <Publisher>Bantam Books</Publisher>
  <year month="December">1985</year>
 </book>
</bibliography>

You can use double quotes or single quotes. If the attribute value itself contains double quotes you can use single quotes.


Entity References

Some characters have a special meaning in XML.


You have to use the letters (the column on the left) instead of the symbols (central column).


Comments in XML

The XML comment is optional. If it exists, it must follow rules

  • <!-- This is a comment -->
  • Two dashes in the middle of a comment are not allowed.


XML Stores New Line as LF [5]


  • Windows applications store a new line as carriage return and line feed (CR+LF)
  • Unix and Mac OSX uses LF
  • Old Mac systems use CR
  • XML stores a new line as LF




References
[1] https://en.wikipedia.org/wiki/Rex_Stout_bibliography
[1] https://it.wikipedia.org/wiki/Rex_Stout
[2] https://en.m.wikipedia.org/wiki/XML_tree
[3] https://www.w3schools.com/xml/xml_tree.asp
[4] https://www.w3schools.com/xml/xml_namespaces.asp
[5] https://www.w3schools.com/xml/xpath_syntax.asp
[6] https://www.w3schools.com/xml/xml_xpath.asp
[7] https://en.m.wikipedia.org/wiki/XML_tree
[8] https://en.wikipedia.org/wiki/XPat

Nessun commento: