XML Guidelines

Basic Guidelines
All opening tags must have accompanying closing tags.

Example  

XML Documents must have a header at the top of the document identifying the XML version and encoding.  XML also includes schema, which describes the data or one or more hierarchical types defining XML documents. 

Data Types
This is a list of the main data types in XML:             </xsd:complexType> This is how to define binary text in XML: <xsd:complexType name="BinaryType">  <xsd:element name="data" type="xsd:hexBinary"/> </xsd:sequence> </xsd:complexType>

Restricting Data Types/ String Length
XML schema can be used to define the range of data types. This example restricts integers to values between 1 and 255: <xsd:simpleType name="GroupType"> <xsd:restriction base="xsd:int"> <xsd:minInclusive value="1"/> <xsd:maxInclusive value="255"/> </xsd:restriction> </xsd:simpleType> XML schema can also be used to restrict group length. This example restricts strings to lengths between 1 and 3: <xsd:simpleType name="ShortNameType"> <xsd:restriction base="xsd:string"> <xsd:minLength value="1"/> <xsd:maxLength value="3"/> </xsd:restriction> </xsd:simpleType>

JAXB
JAXB is an acronym for Java Archetecture for XML Binding. It can be used to parse XML into Java.

To parse Java elements into XML files using JAXB, use the following annotations: @XmlRootElement //represents Java data/class as value in XML document Other annotations include: @XmlElement @XmlEnum

DOM, SAX, and StAX
The three main parsers for parsing XML into Java include DOM (Document Object Model), SAX (Simple Architecture for XML), and StAX (Streaming Architecture for XML). Of the three parsers, the DOM parser is the easiest to use.