I'm following through the w3schools tutorial on xsd and xml validation
and I'm trying to get one of the examples to validate. The problem
seems to be in validating the attributes because if I strip them out,
then it validates fine. I'm blindly following the tutorial but I can't
see anything wrong with the xsd file, so dare I question if there is a
bug?

Stripping out the w3schools example somewhat, if I was to take the
following schema:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>

<!-- definition of attributes -->
<xs:attribute name="orderid" type="xs:string"/>

<xs:element name="shiporder">
 <xs:complexType>
  <xs:attribute ref="orderid" use="required"/>
 </xs:complexType>
</xs:element>

</xs:schema>


An xml file:

<?xml version="1.0" encoding="ISO-8859-1"?>

<shiporder orderid="889923" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance" xsi:noNamespaceSchemaLocation="validator.xsd">

</shiporder>

and a test script:

require 'xml/libxml'
include XML

xsd_string = ""

File.open('validator.xsd', 'r') do |f1|
  while line = f1.gets
    xsd_string += line
  end
end

doc = Document.file('test.xml')

schema = XML::Schema.from_string( xsd_string )

print doc.validate(schema)


Then I get the following errors

>ruby test.rb
false
error -- found validity error: No declaration for attribute orderid of
element shiporder
error -- found validity error: No declaration for attribute
noNamespaceSchemaLocation of element shiporder
error -- found validity error: No declaration for attribute xmlns:xsi
of element shiporder

I would have thought that the attribute declaration of orderid would
avoid the first error, and that the other two attributes wouldn't need
to be declared.

If the examples are really unclear, the complete xml and xsd is
available at http://www.w3schools.com/schema/schema_example.asp

Cheers
_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to