XML Validation Website: 

A User’s Guide

Julien Cuvillier

KC Morris

NISTIR 7829
NISTIR 7829

XML Validation Website: 

A User’s Guide

Julien Cuvillier

KC Morris

Systems Integration Division

Engineering Laboratory

November 2011

U.S. Department of Commerce

John E. Bryson, Secretary

National Institute of Standards and Technology

Patrick D. Gallagher, Under Secretary of Commerce for Standards and Technology and Director
Abstract

This report describes installation and use of the XML (Extensible Markup Language) Validation

Website. The website is one of several tools produced by NIST’s XML Testbed project within

the Manufacturing Systems Integration Division at NIST. These tools aid in producing high

quality XML schemas using a standards-based approach to manufacturing systems integration.

The website provides a central site for testing XML schemas outside of a user’s own operating

environment with a number of externally available XML tools, thereby validating that the

schemas will work in other environments before distribution. The XML Validation website

which hosts a number of XML parsing tools that can be used to remotely validate XML schemas

against the W3C (World Wide Web Consortium) XML Schema standard [1], and XML data

against their corresponding XML schemas.

The website is available at http://www.nist.gov/el/msid/xmltestbed.cfm.

Contents

1 How to use the XML Validation Website 4

1.1 Schema Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.1.1 Upload a Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.1.2 Select a parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.2 Instance Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.2.1 Upload an XML file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.2.2 Select a Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.2.3 Select a parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.3 Accessing the results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2 Adding new features 6

2.1 The configuration file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2.2 Add new default schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2.3 Add a new parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.3.1 Creating a new class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2.3.2 Adding parser to config file . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3 The XML Validator library 9

3.1 Intro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3.2 UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3.3 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3.4 JavaDoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3.4.1 Package Util . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3.4.2 Package beans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3
1 How to use the XML Validation Website

This section provides instructions for the end user of the XML validation website.

1.1 Schema Validation

Schema validation allows the user to upload their own schema file, or a zip file containing

multiple schemas, and validate it against the W3C standard specification for XML schemas [1].

1.1.1 Upload a Schema

The schema can be uploaded as a schema file (”.xsd” or ”.XSD”) or as a zip file containing

multiple schemas. (If a zip file is uploaded, the target schema file name, including the path

starting from the root directory, must be specified). The target schema must have the extension

”.xsd” or ”.XSD”.

1.1.2 Select a parser

The user can select one or more parsers among the list below.

• Xerces 2.9.1 [2]

• JING 20081028 [3]

• MSV 20081113 [4]

1.2 Instance Validation

Instance validation allows the user to upload their own XML instance and validate its content

with either their own uploaded schema, or from a selection of five currently available public

schemas. Other schemas may be added.

• OASIS UBL v1.0 & v2.0 [5]

• OAGIS v9.4.1 [6]

• AIAG [7]

• StratML [8]

• MSX-DMS v1.3 [9]

Note that instance validation is one way to validate that an XML schema meets the requirements

captured in an XML schema. If errors are encountered during instance validation, it may reflect

problems in the XML schema.

4
1.2.1 Upload an XML file

The XML file uploaded must have the extension ”.xml” or ”.XML” and its name cannot contain

any white spaces.

1.2.2 Select a Schema

There are two ways to select a schema:

• The schema can be uploaded as a schema file (”.xsd” or ”.XSD”) or as a zip file containing

multiple schemas. If you uploaded a zip file, you must specify the target schema file name

including the path, starting from the root directory. The target schema must have the

extension ”.xsd” or ”.XSD” and its name cannot contain any white spaces.

• Alternatively, a schema can be selected from the list of schemas installed on the system

(see section 1.2). For the latter, two options exist:

– Select a set of schemas below and set the SchemaLocation attribute at the root of

the XML instance. The SchemaLocation value must correspond with the path of

the file in the expanded listing below.

– Expand the appropriate listing below and select the schema to use.

1.2.3 Select a parser

The user selects at least one parser among the following list:

• Xerces 2.9.1 [2]

• JING 20081028 [3]

• MSV 20081113 [4]

• JAXP 1.4.2 [10]

• LibXml2 2.7.6 [11]

1.3 Accessing the results

The results for both schema and instance validation can be viewed in two ways:

• As a web page, all the results are displayed on the same page, and you have the following

information:

– XML file

– Schema file

5
– Parser name

– Validation output

• Alternatively, by entering your email address the results will be emailed to you in the

form of an xml file. Figure 1 shows an example of the XML files. The schema for the

XML file is provided in Appendix A. Appendix B contains an xslt [12] file for rendering

a results file.

<?xml version=” 1. 0 ”?>

<V ali d a ti o n R e s ul t s xml n s: x si=” h t t p : //www. w3 . o r g /2001/XMLSchema−i n s t a n c e ”

noNamespaceSchemaLocation=” V ali d a ti o n R e s ul t s . xsd ”>

<R e s ul t s>

<P a r s e r>

<Name>Xe rce s</Name>

<V e r si o n>2 . 9 . 1</ V e r si on>

<Output>The output o f the v a l i d a t i o n</Output>

</ P a r s e r>

<F i l e s>

<SchemaFile>schema . xsd</ SchemaFile>

</ F i l e s>

</ R e s ul t s>

</ V ali d a ti o n R e s ul t s>

Figure 1: Results of a schema validation in XML format

2 Adding new features

This section provides instructions for an administrator to add new schemas or parsers to the

website.

2.1 The configuration file

The configuration file is an XML file that contains information about the schema and the parsers

used. This file is used to generate the web pages. Figure 2 is an example of a configuration file.

2.2 Add new default schemas

In order to add a new schema directory, add a new entry in the config file with the following

information: (see figure 2 for an example)

6
• name

• version

• path

• comment (optional)

• url (optional)

<?xml version=” 1. 0 ” enc odin g=”UTF−8”?>

<c o n f i g u r a t i o n>

<p a r s e r s>

<p a r s e r name=” P a r s e r 1 ” version=” 1. 0 ” ID=” 1 ” i n s t a n c e v a l i d a t i o n=” t r u e ”

s c h em a v ali d a ti o n=” t r u e ” needSchemaLocation=” t r u e ”>

<depLocPath>path</ depLocPath>

<c l a s s>u t i l . p a r s e r . P a r s e r 1</ c l a s s>

<comment>comment</comment>

<u r l>h t t p: //www. p a r s e r 1 . com/</ u r l>

</ p a r s e r>

<p a r s e r name=” P a r s e r 2 ” version=” 2 . 0 . 1 ” ID=” 1 ” i n s t a n c e v a l i d a t i o n=” f a l s e ”

s c h em a v ali d a ti o n=” t r u e ” needSchemaLocation=” f a l s e ”>

<depLocPath>path</ depLocPath>

<c l a s s>u t i l . p a r s e r . P a r s e r 2</ c l a s s>

</ p a r s e r>

</ p a r s e r s>

<schemas>

<schema name=”Schemas” version=”NA” ID=”1”>

<path>path</path>

<comment>comment</comment>

<url>http://www.schemas-url.org</url>

</schema>

</schemas>

</ c o n f i g u r a t i o n>

Figure 2: Example of a configuration file with the part related to the schemas highlighted

2.3 Add a new parser

To add a new parser, two modifications are needed: creating a new class and adding the parsers

to the configuration file.

7
2.3.1 Creating a new class

Create a class that extends the class util.Parser in the XMLValidation project and override the

method:

- public String parse(File XMLFile, File SchemaFile)

You can either use Java code or execute a command line (java -jar, execute an executable file,

etc.). To execute a command line, use the method:

String execCommand(String command)

Here are the inputs supported by the arguments:

• XMLFile6=null and SchemaFile6=null Validates the XMLFile against the SchemaFile.

• XMLFile6=null and SchemaFile=null Validates the XMLFile with the Schema given

in the SchemaLocation tag. The SchemaFile is not used.

• XMLFile=null and SchemaFile6=null Validates the SchemaFile with the W3C standard [1].

2.3.2 Adding parser to config file

Add a new entry in the config file with the following information: (see figure 3 for an example)

• name

• version

• ID is used if you want to use different methods of validation with the same parser. (Ex:

DOM and SAX)

• instance validation is used to determine if the parser is able to validate an instance.

• schema validation is used to determine if the parser is able to validate a schema.

• needSchemaLocation is used for the instance validation. Some parsers require that a

SchemaLocation tag appears in the XML File. If the SchemaLocation tag is not present,

an error message will be displayed in the result page.

• depLocPath is the path to the dependencies (jar files, executable, etc.)

• class is the parser’s class (including the packages, ex: util.parser.XERCESParser)

• comment (optional)

• url (optional)

8
<?xml version=” 1. 0 ” enc odin g=”UTF−8”?>

<c o n f i g u r a t i o n>

<parsers>

<parser name=”Parser1” version=”1.0” ID=”1” instance validation=”true”

schema validation=”true” needSchemaLocation=”true”>

<depLocPath>path</depLocPath>

<class>util.parser.Parser1</class>

<comment>comment</comment>

<url>http://www.parser1.com/</url>

</parser>

<parser name=”Parser2” version=”2.0.1” ID=”1” instance validation=”false”

schema validation=”true” needSchemaLocation=”false”>

<depLocPath>path</depLocPath>

<class>util.parser.Parser2</class>

</parser>

</parsers>

<schemas>

<schema name=”Schemas ” version=”NA” ID=” 1 ”>

<path>path</ path>

<comment>comment</comment>

<u r l>h t t p: //www. schemas−u r l . o r g</ u r l>

</ schema>

</ schemas>

</ c o n f i g u r a t i o n>

Figure 3: Example of a configuration file with the part related to the parser highlighted

3 The XML Validator library

This section provides instructions to assist a programmer in modifying the tool.

3.1 Intro

XMLValidator is a library used by the validation page to validate XML Files. This library

contains all the parsers used in the Validation Page but this package can be used in any other

application.

3.2 UML

Figure 4 is a class diagram of the XMLValidator library.

9
Figure 4: XMLValidator Class Diagram

3.3 Example

In this example (figure 5) we will validate an instance XML file (XMLFile) against a schema

(SchemaFile). We will use the parser JING (class: util.parser.JINGParser), its dependencies

are in the directory ”dependencies/”.

// I n i t i a l i z e t h e v a l i d a t o r w i t h t h e temporary d i r e c t o r y

V ali d a t o r v = new V ali d a t o r ( ”temp/ ” ) ;

// Crea te a p a r s e r

ParserBean p a r s e r = new ParserBean ( ” d e p e n d e n ci e s / ” , ” u t i l . p a r s e r . JINGParser ” ) ;

//Run t h e v a l i d a t i o n and p r i n t t h e r e s u l t in t h e d e f a u l t o u t p u t .

System . out . p r i n t l n ( v . v a l i d a t e ( XMLFile , SchemaFile , p a r s e r ) ) ;

Figure 5: Exmaple of the use of the XML Validator library

10
3.4 JavaDoc

3.4.1 Package Util

Class Parser

Abstract class used to represent a parser.

Declaration

public abstract class Parser

extends java.lang.Object

Constructors

• Parser

public Parser( )

Methods

• parse

public abstract String parse( java.io.File XMLFile, java.io.File SchemaFile

)

• setJarLocation

public void setJarLocation( java.lang.String jarLocation )

Class Validator

This class is used to validate an XMLFile against a schema. The parser used is given by the user.

Declaration

public class Validator

extends java.lang.Object

11
Constructors

• Validator

public Validator( java.lang.String tempDir )

Methods

• validate

public String validate( java.io.File XMLFile, java.io.File SchemaFile,

beans.ParserBean parser )

– Usage

∗ Validates the XML File against the SchemaFile.

– Parameters

∗ XMLFile - TXML File to validate

∗ SchemaFile - Schema used for validation

∗ parser - Parser used.

– Returns - Output of the validation.

3.4.2 Package beans

Class ParserBean

Represents a parser used for the validation. It contains:

• Name

• Version

• Location of the directory that contains the dependencies (ex: .jar files)

• Name of class that extends from util.Parser

• Whether it’s used for schema or instance validation, or both

• Comments about the parser

• If the parser is able to validate a Schema

• If the parser is able to validate an Instance

• If the parser needs the SchemaLocation tag in the XML file

• URL where you can find the parser

12
Declaration

public class ParserBean

extends java.lang.Object

Constructors

• ParserBean

public ParserBean( )

• ParserBean

public ParserBean( java.lang.String depLocPath, java.lang.String className )

13
Appendix A

This file is the XML Schema representing the XML file received by the user when he chooses

to receive the results by email. (see figure 1)

<?xml version=” 1. 0 ” enc odin g=” u t f −8” ?>

<x s: schem a xml n s: x s=” h t t p : //www. w3 . o r g /2001/XMLSchema” elementFormDe fault=”

q u a l i f i e d ”>

<x s: el em e n t name=” V ali d a ti o n R e s ul t s ” type=” r e s ul t s T y p e ”></ x s: el em e n t>

<xs:complexType name=” r e s ul t s T y p e ”>

<x s: s e q u e n c e>

<x s: el em e n t name=” R e s ul t s ” maxOccurs=”unbounded ”>

<xs:complexType>

<x s: s e q u e n c e>

<x s: el em e n t name=” P a r s e r ”>

<xs:complexType>

<x s: s e q u e n c e>

<x s: el em e n t name=”Name” type=” x s : s t r i n g ” />

<x s: el em e n t name=” Ve r si on ” type=” x s : s t r i n g ” />

<x s: el em e n t name=”Output ” type=” x s : s t r i n g ” />

</ x s: s e q u e n c e>

</ xs:complexType>

</ x s: el em e n t>

<x s: el em e n t name=” F i l e s ”>

<xs:complexType>

<x s: s e q u e n c e>

<x s: el em e n t name=” SchemaFile ” type=” x s : s t r i n g ” />

<x s: el em e n t name=”XMLFile” type=” x s : s t r i n g ” minOccurs=” 0 ”

maxOccurs=” 1 ” />

</ x s: s e q u e n c e>

</ xs:complexType>

</ x s: el em e n t>

</ x s: s e q u e n c e>

</ xs:complexType>

</ x s: el em e n t>

</ x s: s e q u e n c e>

</ xs:complexType>

</ x s: schem a>

Figure 6: XML Schema for representing the validation results

14
Appendix B

This file is the XSLT document used to transform the validation results (see example XML file

in figure 1 and XML Schema above) in html format.

<?xml version=” 1. 0 ” enc odin g=”ISO−8859−1”?>

<x s l : s t y l e s h e e t version=” 2. 0 ” xml n s: x sl=” h t t p: //www. w3 . o r g /1999/XSL/ Trans form ”>

<x s l : t e m p l a t e match=” / ”>

<x s l : f o r −each s e l e c t=” V ali d a ti o n R e s ul t s / R e s ul t s ”>

<f o n t c o l o r=”#369” s i z e=” 4 ”><s t r o n g>P a r s e r : </ s t r o n g></ f o n t>

<x s l : v a l u e −o f s e l e c t=” P a r s e r /Name” /> v<x s l : v a l u e −o f s e l e c t=” P a r s e r / V e r si o n ” /

><br />

<f o n t c o l o r=”#369” s i z e=” 4 ”><s t r o n g>Schema F i l e : </ s t r o n g></ f o n t>

<x s l : v a l u e −o f s e l e c t=” F i l e s / SchemaFile ” />

< x s l : i f t e s t=” F i l e s /XMLFile”>

<br />

<f o n t c o l o r=”#369” s i z e=” 4 ”><s t r o n g>XML F i l e : </ s t r o n g></ f o n t>

<x s l : v a l u e −o f s e l e c t=” F i l e s /XMLFile” />

</ x s l : i f>

<br /><br />

<f o n t c o l o r=” 6633CC” s i z e=” 5 ”>Output: </ f o n t>

<di v s t y l e=”margin−l e f t : 40px ; ”>

<x s l : v a l u e −o f s e l e c t=” P a r s e r /Output ” di s a bl e −output−e s c a pi n g=” ye s ” />

</ di v>

<br />

<f o n t c o l o r=” 009933 ” s i z e=” 5 ”>P r o c e s si n g Complete</ f o n t>

<br /><br />

</ x s l : f o r −each>

</ x s l : t e m p l a t e>

</ x s l : s t y l e s h e e t>

Figure 7: XSLT

15
References

[1] World Wide Web Consortium. XML Schema. http://www.w3.org/XML/Schema.

[2] APACHE. Xerces Java Parser. http://xerces.apache.org/xerces-j.

[3] Thai Open Source Software Center Ltd. JING: A RELAX NG validator in Java.

http://www.thaiopensource.com/relaxng/jing.html.

[4] SUN. SUN Multi-Schema XML Validator. https://msv.dev.java.net/.

[5] OASIS (Organization for the Advancement of Structured Information Standards). OASIS Universal Business Language (UBL) v2.0.

http://docs.oasis-open.org/ubl/os-UBL-2.0/UBL-2.0.html.

[6] Open Application Group. OAGIS 9.0 Documentation.

http://www.oagi.org/oagi/downloads/oagis/oagis9_doc.htm.

[7] Automotive Industry Action Group. https://www.aiag.org/.

[8] ANSI/AIIM. Strategy Markup Language (StratML). http://www.stratml.net/.

[9] Department of Defense Modeling and Simulation Coordination Office. M&S

community of interest (coi) discovery metadata specification (msc-dms).

http://www.msco.mil/resource_discovery.html.

[10] SUN. Java API for XML Processing. https://jaxp.dev.java.net/.

[11] The XML C parser and toolkit of Gnome. http://xmlsoft.org/.

[12] World Wide Web Consortium. Extensible stylesheet language transformations (xslt) version 2.0. http://www.w3.org/TR/xslt20/.

16