class Nokogiri::XML::DTD - nokogiri-1.15.2 Documentation

# class Nokogiri::XML::DTD

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

### Public Instance Methods

attributes click to toggle source

Get a hash of the attributes for this `DTD`.

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

      Noko_Node_Get_Struct(self, xmlDtd, dtd);

      hash = rb_hash_new();

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

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

      return hash;
    }

each() { |key, value| ... } click to toggle source

    # File lib/nokogiri/xml/dtd.rb, line 17
    def each
      attributes.each do |key, value|
        yield([key, value])
      end
    end

elements click to toggle source

Get a hash of the elements for this `DTD`.

    static VALUE
    elements(VALUE self)
    {
      xmlDtdPtr dtd;
      VALUE hash;

      Noko_Node_Get_Struct(self, xmlDtd, dtd);

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

      hash = rb_hash_new();

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

      return hash;
    }

entities click to toggle source

Get a hash of the elements for this `DTD`.

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

      Noko_Node_Get_Struct(self, xmlDtd, dtd);

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

      hash = rb_hash_new();

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

      return hash;
    }

external_id click to toggle source

Get the External ID for this `DTD`

    static VALUE
    external_id(VALUE self)
    {
      xmlDtdPtr dtd;
      Noko_Node_Get_Struct(self, xmlDtd, dtd);

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

      return NOKOGIRI_STR_NEW2(dtd->ExternalID);
    }

html5_dtd?() click to toggle 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?() click to toggle source

    # File lib/nokogiri/xml/dtd.rb, line 23
    def html_dtd?
      name.casecmp("html").zero?
    end

keys() click to toggle source

    # File lib/nokogiri/xml/dtd.rb, line 13
    def keys
      attributes.keys
    end

notations() → Hash<name(String)⇒Notation> click to toggle source

Returns

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

    static VALUE
    notations(VALUE self)
    {
      xmlDtdPtr dtd;
      VALUE hash;

      Noko_Node_Get_Struct(self, xmlDtd, dtd);

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

      hash = rb_hash_new();

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

      return hash;
    }

system_id click to toggle source

Get the System ID for this `DTD`

    static VALUE
    system_id(VALUE self)
    {
      xmlDtdPtr dtd;
      Noko_Node_Get_Struct(self, xmlDtd, dtd);

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

      return NOKOGIRI_STR_NEW2(dtd->SystemID);
    }

validate(document) click to toggle source

Validate `document` returning a list of errors

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

      Noko_Node_Get_Struct(self, xmlDtd, dtd);
      doc = noko_xml_document_unwrap(document);
      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;
    }