Parent

Class/Module Index [+]

Quicksearch

Nokogiri::XML::Schema

Nokogiri::XML::Schema is used for validating XML against a schema (usually from an xsd file).

Synopsis

Validate an XML document against a Schema. Loop over the errors that are returned and print them out:

xsd = Nokogiri::XML::Schema(File.read(PO_SCHEMA_FILE))
doc = Nokogiri::XML(File.read(PO_XML_FILE))

xsd.validate(doc).each do |error|
  puts error.message
end

The list of errors are Nokogiri::XML::SyntaxError objects.

Attributes

errors[RW]

Errors while parsing the schema file

Public Class Methods

new(string_or_io) click to toggle source

Create a new Nokogiri::XML::Schema object using a string_or_io object.

# File lib/nokogiri/xml/schema.rb, line 36
def self.new string_or_io
  from_document Nokogiri::XML(string_or_io)
end

Public Instance Methods

valid?(thing) click to toggle source

Returns true if thing is a valid Nokogiri::XML::Document or file.

# File lib/nokogiri/xml/schema.rb, line 58
def valid? thing
  validate(thing).length == 0
end
validate(thing) click to toggle source

Validate thing against this schema. thing can be a Nokogiri::XML::Document object, or a filename. An Array of Nokogiri::XML::SyntaxError objects found while validating the thing is returned.

# File lib/nokogiri/xml/schema.rb, line 45
def validate thing
  if thing.is_a?(Nokogiri::XML::Document) 
    validate_document(thing) 
  elsif File.file?(thing)
    validate_file(thing)
  else
    raise ArgumentError, "Must provide Nokogiri::Xml::Document or the name of an existing file"
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.