Olivier
Olivier

Reputation: 1

Validate format and content of XSD file

I searched under and over for this, but I think I am not using the correct words for my query.

I need to validate the format and content of an XML Schema (xsd) file. I also need to do this by command line. To give more guidance, I would like something like the Eclipse schema editor as an example (but by command line).

Let's say I have this schema:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
  targetNamespace="http://www.example.org/ExampleXMLSchema" 
  xmlns:tns="http://www.example.org/ExampleXMLSchema" 
  xmlns:external="http://www.example.org/ExternalXMLSchema" 
  elementFormDefault="unqualified">

    <import schemaLocation="ExternalXMLSchema.xsd" 
      namespace="http://www.example.org/ExternalXMLSchema">
    </import>
    <complexType name="ExampleComplexType">
      <sequence>
        <element name="ExternalElement" 
          type="external:ExternalComplexType"></element>
      </sequence>
    </complexType>
</schema>

I want a tool that validate the format (no missing brackets, no missing end tags, etc), but also make sure that external references are correct. In this example, it would fail if the validator could not find the ExternalXMLSchema.xsd file and its types.

The eclipse editor gives this error for this situation:

src-resolve: Cannot resolve the name 'external:ExternalComplexType' to a(n) 'type definition' component.

Thanks for taking a look at this! Sorry if something is not clear, first post here, trying my best.

Upvotes: 0

Views: 228

Answers (1)

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25034

Any schema validator will have the schema for schema documents built in, so any schema validator should be in a position to validate a schema document.

Checking for bad external references goes beyond checking the schema-validity of the schema document; with some validators I have used, the validator checks external references if you ask it to validate a schema document; with others, it doesn't.

So in general the most reliable way of getting a validator to check a schema document is to attempt to use it to validate an XML instance. I find it convenient to have an instance with a well understood validity error. If the validator issues an error message concerning that problem in the XML instance, the schema is OK; if the validator issues no error messages at all, it's not building the schema or something else is wrong. If it issues a list of complaints about problems in the schema, well, that's what you were looking for, wasn't it?

Among schema validators which can be invoked from the command line are Xerces-J, Xerces-C, Saxon, msv, and libxml (but n.b. libxml's support for XSD is incomplete).

Upvotes: 1

Related Questions