Validating XML in a Graph

Because XML is text, you can edit the XML before applying it to a graph. If you do this, you must ensure that the XML file continues to be valid, according to the Document Type Definition (DTD) for the graph.

Validating an XML graph

By default, if there are structure errors in the XML, then the graph ignores the erroneous lines in the XML. For example, if the XML has the following lines in it, then the graph does not set the Visible property of the X1Title. Instead, the graph uses the previous value. The graph does set the Visible property of the Y1Title.


<X1Title visble = true> </X1Title> <Y1Title visible = true> </Y1Title>

The readXML or setXML method does not throw a BIParseException if the XML contains only validation errors. You can specify validation of the XML, so that readXML and setXML throw the BIParseException when the XML is not valid according to the DTD. The BIParseException gives you explicit messages about any problems that the parser finds in the XML. To do this, you call setXMLValidated, as shown in the following example.


Graph myGraph = new Graph(); myGraph.setXMLValidated(true);

After calling these lines, if you try to apply the invalid XML, then readXML or setXML throws a BIParseException. As it does without validation, the graph ignores the "visble" attribute in the XML.