Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Friday, September 30, 2011

Validating XML without Namespaces

In the Recordare MusicXML standard for transmitting musical scores, the toplevel elements don't use a namespace.  That is, there was no targetNamespace attribute with the xs:schema element in the XSDs.

From the standard

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink" elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:element name="score-partwise" block="extension substitution" final="#all">

The lack of a namespace is legal and is used to support an XSD authoring technique called "Chameleon Namespace Design".  This technique allows -- through an xs:include directive -- another schema to absorb the elements and types into another namespace.  Instead of defining a different namespace in each XSD, all XSDs are brought under a single namespace.   This post describes the background of the Chameleon technique.

This enables a standard to promote types to be used in a vendor-specific schema without being locked to a namespace.  However, everything can still be validated to ensure compatibility.


<xsd:include schemaLocation="MusicXML.xsd"/>  
<!-- include in 'MySheetMusicApp.xsd' with its own namespace -->

To validate, use the noNamespaceSchemaLocation attribute on the toplevel element of an XML document.  For example,

<score-partwise version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="C:\Documents\MusicXMLProject\musicxml.xsd">

No comments:

Post a Comment