/
xml_element_decl.c
69 lines (57 loc) · 1.39 KB
/
xml_element_decl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <nokogiri.h>
VALUE cNokogiriXmlElementDecl;
static ID id_document;
/*
* call-seq:
* element_type → Integer
*
* The element_type
*/
static VALUE
element_type(VALUE self)
{
xmlElementPtr node;
Noko_Node_Get_Struct(self, xmlElement, node);
return INT2NUM(node->etype);
}
/*
* call-seq:
* content → Nokogiri::XML::ElementContent
*
* [Returns] The root of this element declaration's content tree.
*/
static VALUE
content(VALUE self)
{
xmlElementPtr node;
Noko_Node_Get_Struct(self, xmlElement, node);
if (!node->content) { return Qnil; }
return noko_xml_element_content_wrap(
rb_funcall(self, id_document, 0),
node->content
);
}
/*
* call-seq:
* prefix → String
*
* [Returns] The namespace +prefix+ for this element declaration.
*/
static VALUE
prefix(VALUE self)
{
xmlElementPtr node;
Noko_Node_Get_Struct(self, xmlElement, node);
if (!node->prefix) { return Qnil; }
return NOKOGIRI_STR_NEW2(node->prefix);
}
void
noko_init_xml_element_decl(void)
{
assert(cNokogiriXmlNode);
cNokogiriXmlElementDecl = rb_define_class_under(mNokogiriXml, "ElementDecl", cNokogiriXmlNode);
rb_define_method(cNokogiriXmlElementDecl, "element_type", element_type, 0);
rb_define_method(cNokogiriXmlElementDecl, "content", content, 0);
rb_define_method(cNokogiriXmlElementDecl, "prefix", prefix, 0);
id_document = rb_intern("document");
}