XML special character secrets
Note that the end of the XML root has a closing tag:
All elements in XML must have an opening and closing tag. This, in addition to the root is the definition of a "well-formed XML document". By the way, all tags in XML are case sensitive. A good XML coding practice is to make all of the tags uppercase. Doing this also makes the structure of the XML stand out when you read it.
Add child elements
Child elements are used to provide additional data and information about the enclosing XML element (i.e. in the example above). Note that XML does not require the same set of child elements for each enclosing XML element, making upgrading or changing your elements easy. However, your parser does have to handle this situation! Child elements are XML elements underneath the root (OBJECTID, OBJECTSERVERID, OBJECTTYPE, OBJECTFLAGS, RASPICONNECTSERVERVERSIONNUMBER, RESPONSE). All of these tags must have a beginning and ending tag similar to the root. In addition, all elements can have child elements nested inside.
XML elements can have attributes, just like HTML. Attributes provide additional information about an element. By convention, attributes are usually given in lower case. It is good practice to use attributes in XML sparingly and in a consistent manner. You can rewrite the above XML as the following:
Not having attributes makes the parsing of the XML easier in many ways.
There are two characters that are not allowed inside of an XML element. They are the "<" and "&". The ">" character is allowed, but it is also good practice to replace this character. The pre-defined entity references in XML for these characters are "<", "&" and ">".
Sending special data in XML
Sometimes you want to send general data in your XML element without replacing special characters. For example, you might want to send an HTML page inside an XML element (the RasPiConnect application does this) and you don't want to change all the characters. XML parses all text inside elements by default, but there is a way to change that: CDATA. Inside a CDATA structure, the XML parser ignores the data and it can be passed without change in an XML message. CDATA looks like this:
<![CDATA[<XML & DOES & NOT <LIKETHIS>]]>
Validate your XML
There are many sites on the web that will validate that your XML is well formed. http://www.xmlvalidation.com is one such site. Cut and paste the XML from the first page to try it out.
XML is a simple, easily understood method for sending information in a hardware and software independent manner. The main advantages of XML are readability and portability between systems. It provides an easily extensible framework for information interchange. To learn more about XML try the following websites: http://www.w3schools.com/xml/http://www.quackit.com/xml/tutorial/