I'm trying to load a SAML Protocol schema (specificly this: https://www.oasis-open.org/committees/download.php/3407/oasis-sstc-saml-schema-protocol-1.1.xsd) but after doing this:
schema = Nokogiri::XML::Schema(File.read('saml11_schema.xsd'))
I'm getting 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 googling the error but there are no clues on what might be happening, could someone shed some light?
Note: Using RVM with Ruby 1.8.7-p370
If all your .xsd files are in the same place, and all namespaces are declared like
<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 to open all depending schemas.
If you reference remote schemas, download them and put them all together in a single directory. If you already have the xsd files in your machine, just put them together in the same directory. Then change your xsd to use a relative path. For example:
Change this
<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 validation code inside a Dir.chdir call. 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With