Yes, you're right. validate_schema is listed as a method of
XML::Document but never appears in the method description. Unless
there is a ruby syntax quirk I'm not aware of.

I did see the validate_schema method in the top right hand methods
list, but it says validate_schema(XML::Document), rather than
validate_schema(XML::Schema) which confused me somewhat.

Unfortunately I've just found out that xmllint doesn't insert missing
default values. Well, at least I can validate now.

Thanks

On Jan 9, 3:19 pm, "Sam M." <[EMAIL PROTECTED]> wrote:
> Hi Glenn,
>
> I've just been trying to figure out why I couldn't get XSD validation
> to work at all, never mind if I stripped out the attributes, and I
> just spotted a validate_schema method of XML::Document that made
> validation instantly work for me.
>
> So the code you have above would look something like this:
>
>     ...
>     document = XML::Document.file("test.xml")
>     schema = XML::Schema.from_string(xsd_string)
>     ...
>
> document.validate_schema(schema)     # should return true if your doc
> matches your schema
>
> Incidentally I couldn't find this method mentioned in the rdocs
> anywhere I only saw it by spotting it in the list of methods of
> XML::Document. For example in an irb session:
>
> document = XML::Document.new
> document.methods.sort                # prints out all methods that
> document responds to
>
> On Jan 7, 6:14 am, GlennNZ <[EMAIL PROTECTED]> wrote:
>
> > 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 athttp://www.w3schools.com/schema/schema_example.asp
>
> > Cheers
> > _______________________________________________
> > libxml-devel mailing list
> > [EMAIL PROTECTED]://rubyforge.org/mailman/listinfo/libxml-devel
>
> _______________________________________________
> libxml-devel mailing list
> [EMAIL PROTECTED]://rubyforge.org/mailman/listinfo/libxml-devel
_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to