XML Validation

Introduction

For user convenience, the Davisor Chart has not paid attention to lowercase and uppercase letters in XML. The support of this convenience continues. However, there are cases in which it is wanted that the XML from which a chart is created is valid to the letter.

With XML validation, it can be made sure that a chart is created only if the XML is valid. Invalid XML will create an error that stops the chart generation. For example, if validation is done, an XML file with a charttype attribute in the <attributes> tag would generate an error, because the attribute should be written as chartType .

XML Schema

For being able to validate XML, the rules for valid XML have to exist. The rules for the structure of XML are defined with W3C XML schema. Davisor Chart download package includes Davisor Chart XML schema file.

System Requirements

The validation of XML requires an XML parser that has an SAX 2.0 driver that implements an XMLReader interface. One example of such a parser is Xerces2 Java Parser. The jar files of the XML parser, which are xercesImpl.jar and xml-apis.jar in the case of Xerces, should be installed into a suitable directory of your web server. Find out from the documentation of your web server where the jar files should be installed.

Validating XML

Davisor Chart does not validate XML by default. Turning validation on is simple. For validating XML, just change one line of the XML code that is used for creating chart. Change the line of:

<chart>

to the form of:

<chart
  xmlns="http://www.davisor.com/chart/xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.davisor.com/chart/xsd
    http://your.server.address/chart/doctypes/davisorchart-4.1.xsd">

The last line of the changed <chart> tag tells the location of the XML schema. If the XML schema is not found from the given location, the XML file is not validated. You can change the location of the XML schema file to be what you want. If you do not move the XML schema, the address of the XML schema in your web server should be:

http://your.server.address/chart/doctypes/davisorchart-4.1.xsd

after downloading and deploying Davisor Chart into your web server.

Examples

The use of both XML code examples below produce the following image. The first XML example does not have XML validation, but the second one has.

Same result with and without validation.

Code without XML validation.

<chart>
  <data>
    <column type="value" values="30 34 30 36"/>
    <column type="label" values="A B C D"/>
  </data>
  <attributes chartType="column"> 
    <image height="200" width="300" />
    <axes font="Arial-14"/>
  </attributes>
</chart>

Code with XML validation.

<chart
  xmlns="http://www.davisor.com/chart/xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.davisor.com/chart/xsd
    http://your.server.address/chart/doctypes/davisorchart-4.1.xsd">
  <data>
    <column type="value" values="30 34 30 36"/>
    <column type="label" values="A B C D"/>
  </data>
  <attributes chartType="column"> 
    <image height="200" width="300" />
    <axes font="Arial-14"/>
  </attributes>
</chart>