Class: Nokogiri::XML::DTD

Inherits:
Node
  • Object
show all
Defined in:
lib/nokogiri/xml/dtd.rb,
ext/nokogiri/xml_dtd.c

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Nokogiri::XML::Node

Instance Method Details

#attributesObject

Get a hash of the attributes for this DTD.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'ext/nokogiri/xml_dtd.c', line 80

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;
}

#eachObject



16
17
18
19
20
# File 'lib/nokogiri/xml/dtd.rb', line 16

def each
  attributes.each do |key, value|
    yield([key, value])
  end
end

#elementsObject

Get a hash of the elements for this DTD.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'ext/nokogiri/xml_dtd.c', line 102

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;
}

#entitiesObject

Get a hash of the elements for this DTD.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'ext/nokogiri/xml_dtd.c', line 36

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;
}

#external_idObject

Get the External ID for this DTD



170
171
172
173
174
175
176
177
178
# File 'ext/nokogiri/xml_dtd.c', line 170

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);
}

#html5_dtd?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/nokogiri/xml/dtd.rb', line 26

def html5_dtd?
  html_dtd? &&
    external_id.nil? &&
    (system_id.nil? || system_id == 'about:legacy-compat')
end

#html_dtd?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/nokogiri/xml/dtd.rb', line 22

def html_dtd?
  name.casecmp('html').zero?
end

#keysObject



12
13
14
# File 'lib/nokogiri/xml/dtd.rb', line 12

def keys
  attributes.keys
end

#notationsObject

Get a hash of the notations for this DTD.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'ext/nokogiri/xml_dtd.c', line 58

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;
}

#system_idObject

Get the System ID for this DTD



154
155
156
157
158
159
160
161
162
# File 'ext/nokogiri/xml_dtd.c', line 154

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);
}

#validate(document) ⇒ Object

Validate document returning a list of errors



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'ext/nokogiri/xml_dtd.c', line 124

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;
}