Posts in current category
May 27, 2021 17:00 XML
XML elements are an integral part of an XML document, and we can think of an XML element as a container that holds text, elements, properties, media objects, or all of that.
The XML document contains XML elements.
Each XML document contains one or more elements whose scope is either separated by the start and end markers, or empty elements, with an empty element label.
XML elements refer to the portion of the label that starts (and includes) the label until (and includes) the end label.
An element can contain:
<bookstore> <book category="CHILDREN"> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title>Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>
In the example above,
because they contain other elements.
text content because
they contain text.
XML elements must follow the following naming rules:
You can use any name, no reserved words.
Make the name descriptive.
It's also good to use
The name should be short and
If you name it this way:
some software will think you want
If you name it this way:
some software will
to be a property of the
Colons are converted to namespaces for use (more on that later).
XML documents often have a corresponding database, where the fields correspond to elements in the XML document. A practical experience is to use the naming rules of the database to name elements in an XML document.
In XML, non-English letters such as the one are
legal, but it's important to note that there may be problems when your software vendor doesn't support these characters.
XML elements are extensable to carry more information.
Take a look at the following example of XML:
<note> <to>小明</to> <from>小狮妹</from> <body>周末别忘记学习编程哦~</body> </note>
Let's imagine that we've created an application that
extracts the elements from
the XML document and produces the following output:
Don't forget to learn programming at the weekend
Imagine some additional information added by the author of the XML document:
<note> <date>2020-09-09</date> <to>小明</to> <from>小狮妹</from> <heading>提醒</heading> <body>周末别忘记学习编程哦~</body> </note>
So will the app break or crash?
The application can still find the elements in the
XML documentation, and
produce the same output.
One of the advantages of XML is that it can scale without interrupting the application.
That's all about XML elements, and you need to be aware that in XML, all elements must have an end tag!