Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating XML using multiple XSD's in Ruby

I'm generating a lot of XMPP stanzas, and want to validate them against the specs available here in my unit tests.

At the moment I am using Nokogiri to achieve this with something like

xml    = Nokogiri::XML( xmpp_stanza)
schema = Nokogiri::XML::Schema( xmpp_schema )

assert schema.valid?( xml )

Now this works fine except it gets reported as invalid because each schema only covers one namespace, and my XMPP stanzas have multiple namespaces. For example:

Invalid XML: Element '{http://jabber.org/protocol/pubsub}pubsub': No matching global element declaration available, but demanded by the strict wildcard.

How am I meant to handle multiple schemas to validate a single stanza? Am I meant to first split it apart by namespace and validate each one in isolation?

like image 927
Theozaurus Avatar asked Nov 20 '09 12:11

Theozaurus


1 Answers

I was able to achieve this by importing one schema into the other.

e.g.

<xs:import namespace="http://base.google.com/ns/1.0" schemaLocation="public/xsd/google_base.xsd"/>  
like image 99
Sam Avatar answered Sep 27 '22 17:09

Sam