-
-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: improve documentation for XML::{Schema,RelaxNG}
- Loading branch information
1 parent
4631a8a
commit ce9e3ff
Showing
4 changed files
with
231 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,66 @@ | ||
# coding: utf-8 | ||
# frozen_string_literal: true | ||
|
||
module Nokogiri | ||
module XML | ||
class << self | ||
### | ||
# Create a new Nokogiri::XML::RelaxNG document from +string_or_io+. | ||
# See Nokogiri::XML::RelaxNG for an example. | ||
def RelaxNG(string_or_io, options = ParseOptions::DEFAULT_SCHEMA) | ||
RelaxNG.new(string_or_io, options) | ||
# | ||
# :call-seq: | ||
# RelaxNg(input) → Nokogiri::XML::RelaxNG | ||
# RelaxNg(input, parse_options) → Nokogiri::XML::RelaxNG | ||
# | ||
# Parse a RELAX NG schema definition and create a new Schema object. This is a convenience | ||
# method for Nokogiri::XML::RelaxNG.new | ||
# | ||
# See related: Nokogiri::XML::RelaxNG.new | ||
# | ||
# [Parameters] | ||
# - +input+ (String, IO) RELAX NG schema definition | ||
# - +parse_options+ (Nokogiri::XML::ParseOptions) | ||
# Defaults to ParseOptions::DEFAULT_SCHEMA | ||
# | ||
# [Returns] Nokogiri::XML::RelaxNG | ||
# | ||
def RelaxNG(input, parse_options = ParseOptions::DEFAULT_SCHEMA) | ||
RelaxNG.new(input, parse_options) | ||
end | ||
end | ||
|
||
### | ||
# Nokogiri::XML::RelaxNG is used for validating XML against a | ||
# RelaxNG schema. | ||
# Nokogiri::XML::RelaxNG is used for validating XML against a RELAX NG schema definition. | ||
# | ||
# == Synopsis | ||
# *Example:* Determine whether an XML document is valid. | ||
# | ||
# Validate an XML document against a RelaxNG schema. Loop over the errors | ||
# that are returned and print them out: | ||
# schema = Nokogiri::XML::RelaxNG(File.read(RELAX_NG_FILE)) | ||
# doc = Nokogiri::XML(File.read(XML_FILE)) | ||
# schema.valid?(doc) # Boolean | ||
# | ||
# schema = Nokogiri::XML::RelaxNG(File.open(ADDRESS_SCHEMA_FILE)) | ||
# doc = Nokogiri::XML(File.open(ADDRESS_XML_FILE)) | ||
# *Example:* Validate an XML document against a RelaxNG schema, and capture any errors that are found. | ||
# | ||
# schema.validate(doc).each do |error| | ||
# puts error.message | ||
# end | ||
# schema = Nokogiri::XML::RelaxNG(File.open(RELAX_NG_FILE)) | ||
# doc = Nokogiri::XML(File.open(XML_FILE)) | ||
# errors = schema.validate(doc) # Array<SyntaxError> | ||
# | ||
# The list of errors are Nokogiri::XML::SyntaxError objects. | ||
# | ||
# NOTE: RelaxNG input is always treated as TRUSTED documents, meaning that they will cause the | ||
# underlying parsing libraries to access network resources. This is counter to Nokogiri's | ||
# "untrusted by default" security policy, but is a limitation of the underlying libraries. | ||
# ⚠ RELAX NG input is always treated as *trusted*, meaning that the underlying parsing libraries | ||
# *will access network resources*. This is counter to Nokogiri's "untrusted by default" security | ||
# policy, but is an unfortunate limitation of the underlying libraries. Please do not use this | ||
# class for untrusted schema documents. | ||
class RelaxNG < Nokogiri::XML::Schema | ||
# :call-seq: | ||
# new(input) → Nokogiri::XML::RelaxNG | ||
# new(input, parse_options) → Nokogiri::XML::RelaxNG | ||
# | ||
# Parse a RELAX NG schema definition and create a new Schema object. | ||
# | ||
# [Parameters] | ||
# - +input+ (String, IO) RELAX NG schema definition | ||
# - +parse_options+ (Nokogiri::XML::ParseOptions) | ||
# Defaults to ParseOptions::DEFAULT_SCHEMA | ||
# | ||
# [Returns] Nokogiri::XML::RelaxNG | ||
# | ||
def self.new(input, parse_options = ParseOptions::DEFAULT_SCHEMA) | ||
from_document(Nokogiri::XML(input), parse_options) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.