Class: LibXML::XML::RelaxNG
- Inherits:
-
Object
- Object
- LibXML::XML::RelaxNG
- Defined in:
- ext/libxml/ruby_xml_relaxng.c,
ext/libxml/ruby_xml_relaxng.c
Overview
The XML::RelaxNG class is used to prepare RelaxNG schemas for validation of xml documents.
Schemas can be created from XML documents, strings or URIs using the corresponding methods (new for URIs).
Once a schema is prepared, an XML document can be validated by the XML::Document#validate_relaxng method providing the XML::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 collapse
-
.XML::RelaxNG.document(document) ⇒ Object
Create a new relaxng from the specified document.
-
.XML::RelaxNG.string("relaxng_data") ⇒ Object
Create a new relaxng using the specified string.
-
.XML::Relaxng.new(relaxng_uri) ⇒ Object
Create a new relaxng from the specified URI.
Class Method Details
.XML::RelaxNG.document(document) ⇒ Object
Create a new relaxng from the specified document.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'ext/libxml/ruby_xml_relaxng.c', line 78
static VALUE rxml_relaxng_init_from_document(VALUE class, VALUE document)
{
xmlDocPtr xdoc;
xmlRelaxNGPtr xrelaxng;
xmlRelaxNGParserCtxtPtr xparser;
TypedData_Get_Struct(document, xmlDoc, &rxml_document_data_type, xdoc);
xparser = xmlRelaxNGNewDocParserCtxt(xdoc);
xrelaxng = xmlRelaxNGParse(xparser);
xmlRelaxNGFreeParserCtxt(xparser);
if (!xrelaxng)
rxml_raise(xmlGetLastError());
return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
}
|
.XML::RelaxNG.string("relaxng_data") ⇒ Object
Create a new relaxng using the specified string.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'ext/libxml/ruby_xml_relaxng.c', line 102
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);
if (!xrelaxng)
rxml_raise(xmlGetLastError());
return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
}
|
.XML::Relaxng.new(relaxng_uri) ⇒ Object
Create a new relaxng from the specified URI.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'ext/libxml/ruby_xml_relaxng.c', line 55
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);
if (!xrelaxng)
rxml_raise(xmlGetLastError());
return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
}
|