[libxml-devel] XML Schema validation of multiple namespaces in a document

avatar382 avatar382 at gmail.com
Wed Nov 19 14:48:26 EST 2008


Hi all,

I'll ask the question in one sentence first, and then I'll explain
what I am trying to do.

Does libxml-ruby provide a way to validate a document against multiple
XML Schemas such that any XML in different namespaces, with other XML
Schemas mapped to the namespaces in an xsi:schemaLocation attribute on
the root element are validated against their respective schemas if
they are present?

Example document:

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<FOO:foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:FOO="http://foo.org/FOO"
xmlns:BAR="http://bar.org"
xmlns:BAZ="http://baz.org"
xsi:schemaLocation="http://foo.org http://foo.org/foo.xsd
http://bar.org http://bar.org/bar.xsd">
  <FOO:xmlData>
    <BAR:bar>42</BAR:bar>
  </FOO:xmlData>
  <FOO:xmlData>
    <BAZ:baz>some text</BAZ:baz>
  </FOO:xmlData>
</FOO:foo>

So in this example, there is a snippet of XML in the BAR namespace,
and another in the BAZ namespace. The xsi:schemaLocation attribute has
an XML schema mapped to the BAR namespace, but not to the BAZ
namespace.

I'd like to validate the whole document against the the FOO schema.
With other namespaces, the XML is to be validated if a schema is
present for that namespace, and ignored otherwise.

My ruby code currently looks like this:

doc = LibXML::XML::Document.file path_to_xml_file
schema = LibXML::XML::Schema.new url_to_foo_schema

puts doc.validate_schema schema

The document is validating, even though the XML in the BAR namespace
doesn't conform to the Schema for the BAR namespace.

 Thanks!


More information about the libxml-devel mailing list