class Nokogiri::XML::Schema


schema.valid?(doc) # Boolean
doc = Nokogiri::XML::Document.parse(File.read(XML_FILE))
schema = Nokogiri::XML::Schema.from_document(schema_doc)
schema_doc = Nokogiri::XML::Document.parse(File.read(RELAX_NG_FILE))
Example: Validate an XML document using a Document containing an XSD schema definition.
errors = schema.validate(doc) # Array<SyntaxError>
doc = Nokogiri::XML::Document.parse(File.read(XML_FILE))
schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))
Example: Validate an XML document against an XSD schema, and capture any errors that are found.
schema.valid?(doc) # Boolean
doc = Nokogiri::XML::Document.parse(File.read(XML_FILE))
schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))
Example: Determine whether an XML document is valid.
to Nokogiri’s “untrusted by default” security policy.
🛡 Before v1.11.0, documents were “trusted” by default during schema parsing which was counter
resolution over a network connection.
caller may turn off the NONET option via the ParseOptions to (re-)enable external entity
not resolved from the network (http:// or ftp://). When parsing a trusted document, the
⚠ Since v1.11.0, Schema treats inputs as untrusted by default, and so external entities are
Nokogiri::XML::Schema is used for validating XML against an XSD schema definition.

def self.new(input, parse_options_ = ParseOptions::DEFAULT_SCHEMA, parse_options: parse_options_)


[Returns] Nokogiri::XML::Schema

Defaults to Nokogiri::XML::ParseOptions::DEFAULT_SCHEMA
- +parse_options+ (Nokogiri::XML::ParseOptions)
- +input+ (String | IO) \XSD schema definition
[Parameters]

Parse an \XSD schema definition from a String or IO to create a new Nokogiri::XML::Schema

new(input, parse_options) → Nokogiri::XML::Schema
new(input) → Nokogiri::XML::Schema
:call-seq:
def self.new(input, parse_options_ = ParseOptions::DEFAULT_SCHEMA, parse_options: parse_options_)
  from_document(Nokogiri::XML::Document.parse(input), parse_options)
end

def self.read_memory(...)

Convenience method for Nokogiri::XML::Schema.new

read_memory(input, parse_options) → Nokogiri::XML::Schema
read_memory(input) → Nokogiri::XML::Schema
:call-seq:
def self.read_memory(...)
  # TODO deprecate this method
  new(...)
end

def valid?(input)


return unless schema.valid?("/path/to/file.xml")
schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))

*Example:* Validate an \XML document on disk

return unless schema.valid?(document)
schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))

*Example:* Validate an existing XML::Document

[Returns] Boolean

A parsed document, or a string containing a local filename.
- +input+ (Nokogiri::XML::Document | String)
[Parameters]

Validate +input+ and return a Boolean indicating whether the document is valid

:call-seq: valid?(input) → Boolean
def valid?(input)
  validate(input).empty?
end

def validate(input)


errors = schema.validate("/path/to/file.xml")
schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))

*Example:* Validate an \XML document on disk, and capture any errors that are found.

errors = schema.validate(document)
schema = Nokogiri::XML::Schema.new(File.read(XSD_FILE))

*Example:* Validate an existing XML::Document, and capture any errors that are found.

[Returns] Array

A parsed document, or a string containing a local filename.
- +input+ (Nokogiri::XML::Document | String)
[Parameters]

Validate +input+ and return any errors that are found.

:call-seq: validate(input) → Array
def validate(input)
  if input.is_a?(Nokogiri::XML::Document)
    validate_document(input)
  elsif File.file?(input)
    validate_file(input)
  else
    raise ArgumentError, "Must provide Nokogiri::XML::Document or the name of an existing file"
  end
end