W3cubDocs

/Nokogiri

class Nokogiri::XML::DTD

Parent:
cNokogiriXmlNode

Nokogiri::XML::DTD wraps DTD nodes in an XML document

Public Instance Methods

attributes Show source
static VALUE
attributes(VALUE self)
{
  xmlDtdPtr dtd;
  VALUE hash;

  Data_Get_Struct(self, xmlDtd, dtd);

  hash = rb_hash_new();

  if (!dtd->attributes) { return hash; }

  xmlHashScan((xmlHashTablePtr)dtd->attributes, element_copier, (void *)hash);

  return hash;
}

Get a hash of the attributes for this DTD.

each() { |key, value| ... } Show source
# File lib/nokogiri/xml/dtd.rb, line 17
def each
  attributes.each do |key, value|
    yield([key, value])
  end
end
elements Show source
static VALUE
elements(VALUE self)
{
  xmlDtdPtr dtd;
  VALUE hash;

  Data_Get_Struct(self, xmlDtd, dtd);

  if (!dtd->elements) { return Qnil; }

  hash = rb_hash_new();

  xmlHashScan((xmlHashTablePtr)dtd->elements, element_copier, (void *)hash);

  return hash;
}

Get a hash of the elements for this DTD.

entities Show source
static VALUE
entities(VALUE self)
{
  xmlDtdPtr dtd;
  VALUE hash;

  Data_Get_Struct(self, xmlDtd, dtd);

  if (!dtd->entities) { return Qnil; }

  hash = rb_hash_new();

  xmlHashScan((xmlHashTablePtr)dtd->entities, element_copier, (void *)hash);

  return hash;
}

Get a hash of the elements for this DTD.

external_id Show source
static VALUE
external_id(VALUE self)
{
  xmlDtdPtr dtd;
  Data_Get_Struct(self, xmlDtd, dtd);

  if (!dtd->ExternalID) { return Qnil; }

  return NOKOGIRI_STR_NEW2(dtd->ExternalID);
}

Get the External ID for this DTD

html5_dtd?() Show source
# File lib/nokogiri/xml/dtd.rb, line 27
def html5_dtd?
  html_dtd? &&
    external_id.nil? &&
    (system_id.nil? || system_id == "about:legacy-compat")
end
html_dtd?() Show source
# File lib/nokogiri/xml/dtd.rb, line 23
def html_dtd?
  name.casecmp("html").zero?
end
keys() Show source
# File lib/nokogiri/xml/dtd.rb, line 13
def keys
  attributes.keys
end
notations() → Hash<name(String)⇒Notation> Show source
static VALUE
notations(VALUE self)
{
  xmlDtdPtr dtd;
  VALUE hash;

  Data_Get_Struct(self, xmlDtd, dtd);

  if (!dtd->notations) { return Qnil; }

  hash = rb_hash_new();

  xmlHashScan((xmlHashTablePtr)dtd->notations, notation_copier, (void *)hash);

  return hash;
}
Returns

All the notations for this DTD in a Hash of Notation name to Notation.

system_id Show source
static VALUE
system_id(VALUE self)
{
  xmlDtdPtr dtd;
  Data_Get_Struct(self, xmlDtd, dtd);

  if (!dtd->SystemID) { return Qnil; }

  return NOKOGIRI_STR_NEW2(dtd->SystemID);
}

Get the System ID for this DTD

validate(document) Show source
static VALUE
validate(VALUE self, VALUE document)
{
  xmlDocPtr doc;
  xmlDtdPtr dtd;
  xmlValidCtxtPtr ctxt;
  VALUE error_list;

  Data_Get_Struct(self, xmlDtd, dtd);
  Data_Get_Struct(document, xmlDoc, doc);
  error_list = rb_ary_new();

  ctxt = xmlNewValidCtxt();

  xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);

  xmlValidateDtd(ctxt, doc, dtd);

  xmlSetStructuredErrorFunc(NULL, NULL);

  xmlFreeValidCtxt(ctxt);

  return error_list;
}

Validate document returning a list of errors

© 2008–2018 Aaron Patterson, Mike Dalessio, Charles Nutter, Sergio Arbeo,
Patrick Mahoney, Yoko Harada, Akinori MUSHA, John Shahid, Lars Kanis
Licensed under the MIT License.
https://nokogiri.org/rdoc/Nokogiri/XML/DTD.html