Class: LibXML::XML::RelaxNG
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | ext/libxml/ruby_xml_relaxng.c, ext/libxml/ruby_xml_relaxng.c |
Overview
The RelaxNG class is used to prepare RelaxNG schemas for validation of xml documents.
Schemas can be created from ::LibXML::XML documents, strings or URIs using the corresponding methods (new for URIs).
Once a schema is prepared, an ::LibXML::XML document can be validated by the Document#validate_relaxng method providing the RelaxNG object as parameter. The method will raise an exception if the document is not valid.
Basic Usage:
# parse schema as xml document
relaxng_document = XML::Document.file('schema.rng')
# prepare schema for validation
relaxng_schema = XML::RelaxNG.document(relaxng_document)
# parse xml document to be validated
instance = XML::Document.file('instance.xml')
# validate
instance.validate_relaxng(relaxng_schema)
Class Method Summary
-
XML::RelaxNG.document(document) ⇒ RelaxNG
Create a new relaxng from the specified document.
-
XML::RelaxNG.string("relaxng_data") ⇒ "value"
Create a new relaxng using the specified string.
-
XML::Relaxng.new(relaxng_uri) ⇒ RelaxNG
constructor
Create a new relaxng from the specified URI.
Constructor Details
XML::Relaxng.new(relaxng_uri) ⇒ RelaxNG
Create a new relaxng from the specified URI.
# File 'ext/libxml/ruby_xml_relaxng.c', line 48
static VALUE rxml_relaxng_init_from_uri(VALUE class, VALUE uri)
{
xmlRelaxNGParserCtxtPtr xparser;
xmlRelaxNGPtr xrelaxng;
Check_Type(uri, T_STRING);
xparser = xmlRelaxNGNewParserCtxt(StringValuePtr(uri));
xrelaxng = xmlRelaxNGParse(xparser);
xmlRelaxNGFreeParserCtxt(xparser);
return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
}
Class Method Details
XML::RelaxNG.document(document) ⇒ RelaxNG
Create a new relaxng from the specified document.
# File 'ext/libxml/ruby_xml_relaxng.c', line 68
static VALUE rxml_relaxng_init_from_document(VALUE class, VALUE document)
{
xmlDocPtr xdoc;
xmlRelaxNGPtr xrelaxng;
xmlRelaxNGParserCtxtPtr xparser;
Data_Get_Struct(document, xmlDoc, xdoc);
xparser = xmlRelaxNGNewDocParserCtxt(xdoc);
xrelaxng = xmlRelaxNGParse(xparser);
xmlRelaxNGFreeParserCtxt(xparser);
return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
}
XML::RelaxNG.string("relaxng_data") ⇒ "value"
Create a new relaxng using the specified string.
# File 'ext/libxml/ruby_xml_relaxng.c', line 89
static VALUE rxml_relaxng_init_from_string(VALUE self, VALUE relaxng_str)
{
xmlRelaxNGParserCtxtPtr xparser;
xmlRelaxNGPtr xrelaxng;
Check_Type(relaxng_str, T_STRING);
xparser = xmlRelaxNGNewMemParserCtxt(StringValuePtr(relaxng_str), (int)strlen(StringValuePtr(relaxng_str)));
xrelaxng = xmlRelaxNGParse(xparser);
xmlRelaxNGFreeParserCtxt(xparser);
return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
}