|
|
XML Syntax
XML Syntax
The syntax for valid XML documents is quite simple, there are just a small amount of rules you need to follow to ensure that your documents will universally readable:
All XML elements must have a closing tag
This is the same as well formed HTML - if you have an element which opens with a
<tag>, you need to close it using </tag>. XML does support singular tags (<tag />), however because of the nature of XML (data storage) these are generally not necessary.
XML Tags are case sensitive
This one is pretty self-explanatory -
<Tag> and <tag> are different tags in XML. We suggest using lowercase for all of your tags and giving each tag a unique name - it will help you remember which tag is which is you don't have tags with the same name and different capitalization.
XML Elements must be properly nested
If you open an element inside another element, it must be closed within that element. For example:
<tag1><tag2>content</tag1></tag2>
is wrong, because tag2 must be closed within the element which it was opened within (tag1). This should be:
<tag1><tag2>content</tag1></tag2>
XML Documents must have a root element
There must be an element in your XML document which is the parent of all other elements. RSS feeds used
<rss> or <rdf:RDF>. Put these at the start (after the document type declaration) and the end of you document, and then fill it with content.
All XML Attributes must be quoted
Although we didn't mention it (because it is incorrect in the specifications), in HTML you can have attributes in tags which do not have quotes around their values;
<img src=/images/image.jpg> will work in most browsers. In XML the specification is much clearly defined and you must includes quotes around the values of your attributes, so would need to use <img src="/images/image.jpg"> in this example.
There are some characters which need to be replaces (Entity references)
How do you describe an XML document in an XML document? Every time you indicated a
<tag>, your XML parser would think that this is a new tag and get confused. In order to do this, you need to replace a set of 5 characters with their entity references within your content.
Page Responses
Currently there have been no responses to this page...
If you have anything to contribute to this tutorial, found a bug, or know a better way of achieving the same goal, please leave your response below.
|