XML Parsing Failed
- Incorrect use of tags is a common cause of XML parsing failure. If a set of XML data is being parsed according to a specific XML Schema Definition, or XSD, then this will partly determine which elements are allowed to appear within it. Tags must also be correctly formed in order to parse successfully. For example, an element whose closing tag has been accidentally omitted will not parse and may cause further problems processing the data appearing later in the XML content. The following example of an element shows opening and closing XML tags with some content between them:
<animal>Cat</animal> - XML element attributes may cause parsing errors if they are not included correctly. An XSD for an application will determine which attributes are allowed for each element. This includes the names of attributes and the types of value they must contain, for example numerical or text string values. Syntax errors with attributes are also common causes of parsing failure, such as failing to include both opening and closing sets of quotes around an attribute value. The following example markup shows a correctly structured attribute:
<employee type="manager">John Smith</employee> - XML elements that are not properly nested will often cause parsing issues, not only for processing their own data but also for other data appearing after them within an XML source. XML elements are tree-structured, which means that they can have parent and child elements. For example, the following XML data demonstrates inclusion of a parent element with some child elements:
<company>
<employee>Mary Smith</employee>
<employee>Mark Jones</employee>
</company>
A common nesting error is to close element tags in the wrong order, as in the following altered example markup where "employee" is closed outside "company" instead of inside it:
<company>
<employee>
Mary Smith
</employee>
<employee>
Mark Jones
</company>
</employee> - XML content may contain text characters of many different types, depending on the encoding that a particular file or XML data source is using. The content of an XML data store includes both the text appearing between the opening and closing element tags and the values appearing as attributes. The following example demonstrates a simple element with "Tree" as its content:
<object>Tree</object>
Certain characters such as punctuation symbols and international alphabetical letters may cause parsing errors in some cases. - Rather than dealing with XML parsing errors when they arise, developers can optionally take the precaution of validating XML data before attempting to use it with any other technologies. Validation involves copying or linking to the content of an XML data source within a Web service such as the W3Schools Validator. Validation for XML highlights any syntax and markup errors found, allowing the developer to address these before using the data.