Nokogiri :: XML :: Schema SyntaxError when loading a schema

I am trying to download the SAML protocol scheme (specifically: https://www.oasis-open.org/committees/download.php/3407/oasis-sstc-saml-schema-protocol-1.1.xsd ), but after that:

schema = Nokogiri::XML::Schema(File.read('saml11_schema.xsd')) 

I get this output:

 Nokogiri::XML::SyntaxError Exception: Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'ref': The QName value '{urn:oasis:names:tc:SAML:1.0:assertion}Assertion' does not resolve to a(n) element declaration. 

Tried a mistake in googling, but there are no clues about what might happen, can someone shed some light?

Note. Using RVM with Ruby 1.8.7-p370

+4
source share
2 answers

If you are referencing remote schemas, download them and put them together in the same directory. If you already have xsd files on your computer, just merge them into one directory. Then change xsd to use relative path. For instance:

Change it

 <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/> 

to

 <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/> 

Then wrap the verification code inside the call to Dir.chdir. Like this:

 Dir.chdir(somewhere) do schema = Nokogiri::XML::Schema(IO.read('your-schema.xsd')) doc = Nokogiri::XML(IO.read(doc_path)) schema.validate(doc) end 

Found a solution in this post:

http://ktulu.com.ar/blog/2011/06/26/resolving-validation-errors-using-nokogiri-and-schemas/

+10
source

If all your .xsd files are in one place and all namespaces are declared as

 <import namespace="urn:...:ns:name-1.0" schemaLocation="name-1.0.xsd"/> 

just use File.open instead of File.read to read the .xsd file

Nokogiri will handle all dependent schemes.

+10
source

All Articles