Using nokogiri to validate xml: finding the line-nr of validation errors?



I am trying to validate pretty large xml-files against a xsd-schema. Nokogiri does this perfectly fine, using the following code:



xsd = Nokogiri::XML::Schema(File.read('batch_schema.xsd'))
doc = Nokogiri::XML(File.read('batch205.xml'))

xsd.validate(doc).each do |error|
puts "#{error.line} :: #{error.message}"
end


Simple enough. Only: error.line is always 65535. Because the xml files we need to check are really huge, it would be really-really helpful to get the line-numbers.


I found this cheatsheet so that is where I found the option to read the line.


In the libxml2 documentation I found you have to enable line-numbers for it to be set. Any idea how to enable line-numbers with nokogiri or get a line-number in a validation-error?


No comments:

Post a Comment