From: Ross Bamford Date: 2006-10-06T20:09:30+09:00 Subject: Re: libxml 0.3.8 - How to validate document with schema ? Hi, On Tue, 2006-10-03 at 06:01 +0900, Peter Fitzgibbons wrote: > Hello all (Ross), > > I'm trying to get libxml to validate an XML::Document using #validate with > an XML::Schema. > > Can one of you describe to me what is wrong ? > irb(main):003:0> xml = XML::Document.new('shiporder.xml') > => > Problem here - The argument to XML::Document.new is interpreted as the XML version to use, rather than as a file to read (notice the XML version is your filename). Try this instead: xml = XML::Document.file('shiporder.xml') # => # # < ... snipped ... > # > irb(main):004:0> sch = XML::Schema.from_string(File.open('shiporder.xsd > ').read) (side note, I'd just use File.read('shiporder.xsd') here). > => # > irb(main):005:0> xml.validate sch > error -- found validity error: no root element Instead of validate, you need to pass your schema to validate_schema: sch = XML::Schema.from_string(File.read('shiporder.xsd')) # => # xml.validate_schema(sch) # => true Hope that helps, Ross -- Ross Bamford - rosco@roscopeco.REMOVE.co.uk