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.


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'ext/nokogiri/xml_dtd.c', line 87

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.


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'ext/nokogiri/xml_dtd.c', line 110

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.


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'ext/nokogiri/xml_dtd.c', line 41

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 identifier for PUBLIC


60
61
62
63
64
65
66
67
68
69
# File 'ext/nokogiri/xml_entity_decl.c', line 60

static VALUE
external_id(VALUE self)
{
  xmlEntityPtr node;
  Data_Get_Struct(self, xmlEntity, node);

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

  return NOKOGIRI_STR_NEW2(node->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.


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'ext/nokogiri/xml_dtd.c', line 64

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 URI for a SYSTEM or PUBLIC Entity


77
78
79
80
81
82
83
84
85
86
# File 'ext/nokogiri/xml_entity_decl.c', line 77

static VALUE
system_id(VALUE self)
{
  xmlEntityPtr node;
  Data_Get_Struct(self, xmlEntity, node);

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

  return NOKOGIRI_STR_NEW2(node->SystemID);
}

#validate(document) ⇒ Object

Validate document returning a list of errors


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'ext/nokogiri/xml_dtd.c', line 133

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