libxml-ruby 5.0.4 → 5.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/HISTORY +10 -6
- data/README.rdoc +1 -1
- data/ext/libxml/extconf.rb +5 -0
- data/ext/libxml/ruby_xml.c +556 -556
- data/ext/libxml/ruby_xml_attributes.h +17 -17
- data/ext/libxml/ruby_xml_document.c +1129 -1129
- data/ext/libxml/ruby_xml_dtd.c +257 -257
- data/ext/libxml/ruby_xml_encoding.c +250 -250
- data/ext/libxml/ruby_xml_error.c +1003 -1003
- data/ext/libxml/ruby_xml_error.h +14 -14
- data/ext/libxml/ruby_xml_html_parser_context.c +351 -351
- data/ext/libxml/ruby_xml_input_cbg.c +188 -188
- data/ext/libxml/ruby_xml_namespace.c +151 -151
- data/ext/libxml/ruby_xml_parser.h +10 -10
- data/ext/libxml/ruby_xml_parser_context.c +1009 -1009
- data/ext/libxml/ruby_xml_parser_options.c +74 -74
- data/ext/libxml/ruby_xml_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
- data/ext/libxml/ruby_xml_sax_parser.c +108 -108
- data/ext/libxml/ruby_xml_version.h +9 -9
- data/lib/libxml/attr.rb +122 -122
- data/lib/libxml/attr_decl.rb +80 -80
- data/lib/libxml/attributes.rb +13 -13
- data/lib/libxml/document.rb +194 -194
- data/lib/libxml/error.rb +95 -95
- data/lib/libxml/hpricot.rb +77 -77
- data/lib/libxml/html_parser.rb +96 -96
- data/lib/libxml/namespace.rb +61 -61
- data/lib/libxml/namespaces.rb +37 -37
- data/lib/libxml/node.rb +323 -323
- data/lib/libxml/parser.rb +102 -102
- data/lib/libxml/sax_callbacks.rb +179 -179
- data/lib/libxml/sax_parser.rb +40 -40
- data/lib/libxml/tree.rb +28 -28
- data/lib/libxml.rb +4 -4
- data/lib/xml/libxml.rb +10 -10
- data/lib/xml.rb +13 -13
- data/libxml-ruby.gemspec +50 -49
- data/test/test_document.rb +140 -140
- data/test/test_document_write.rb +142 -142
- data/test/test_dtd.rb +126 -126
- data/test/test_encoding.rb +126 -126
- data/test/test_error.rb +194 -194
- data/test/test_helper.rb +20 -20
- data/test/test_namespace.rb +58 -58
- data/test/test_node.rb +235 -235
- data/test/test_node_write.rb +93 -93
- data/test/test_parser.rb +333 -333
- data/test/test_reader.rb +364 -364
- data/test/test_xml.rb +168 -168
- metadata +5 -4
@@ -1,108 +1,108 @@
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
-
|
3
|
-
#include "ruby_libxml.h"
|
4
|
-
#include "ruby_xml_sax_parser.h"
|
5
|
-
|
6
|
-
/*
|
7
|
-
* Document-class: LibXML::XML::SaxParser
|
8
|
-
*
|
9
|
-
* XML::SaxParser provides a callback based API for parsing documents,
|
10
|
-
* in contrast to XML::Parser's tree based API and XML::Reader's stream
|
11
|
-
* based API.
|
12
|
-
*
|
13
|
-
* The XML::SaxParser API is fairly complex, not well standardized,
|
14
|
-
* and does not directly support validation making entity, namespace and
|
15
|
-
* base processing relatively hard.
|
16
|
-
*
|
17
|
-
* To use the XML::SaxParser, register a callback class via the
|
18
|
-
* XML::SaxParser#callbacks=. It is easiest to include the
|
19
|
-
* XML::SaxParser::Callbacks module in your class and override
|
20
|
-
* the methods as needed.
|
21
|
-
*
|
22
|
-
* Basic example:
|
23
|
-
*
|
24
|
-
* class MyCallbacks
|
25
|
-
* include XML::SaxParser::Callbacks
|
26
|
-
* def on_start_element(element, attributes)
|
27
|
-
* puts #Element started: #{element}"
|
28
|
-
* end
|
29
|
-
* end
|
30
|
-
*
|
31
|
-
* parser = XML::SaxParser.string(my_string)
|
32
|
-
* parser.callbacks = MyCallbacks.new
|
33
|
-
* parser.parse
|
34
|
-
*
|
35
|
-
* You can also parse strings (see XML::SaxParser.string) and
|
36
|
-
* io objects (see XML::SaxParser.io).
|
37
|
-
*/
|
38
|
-
|
39
|
-
VALUE cXMLSaxParser;
|
40
|
-
static ID CALLBACKS_ATTR;
|
41
|
-
static ID CONTEXT_ATTR;
|
42
|
-
|
43
|
-
|
44
|
-
/* ====== Parser =========== */
|
45
|
-
|
46
|
-
/*
|
47
|
-
* call-seq:
|
48
|
-
* parser.initialize(context) -> XML::Parser
|
49
|
-
*
|
50
|
-
* Creates a new XML::Parser from the specified
|
51
|
-
* XML::Parser::Context.
|
52
|
-
*/
|
53
|
-
static VALUE rxml_sax_parser_initialize(int argc, VALUE *argv, VALUE self)
|
54
|
-
{
|
55
|
-
VALUE context = Qnil;
|
56
|
-
|
57
|
-
rb_scan_args(argc, argv, "01", &context);
|
58
|
-
|
59
|
-
if (context == Qnil)
|
60
|
-
{
|
61
|
-
rb_raise(rb_eArgError, "An instance of a XML::Parser::Context must be passed to XML::SaxParser.new");
|
62
|
-
}
|
63
|
-
|
64
|
-
rb_ivar_set(self, CONTEXT_ATTR, context);
|
65
|
-
return self;
|
66
|
-
}
|
67
|
-
|
68
|
-
/*
|
69
|
-
* call-seq:
|
70
|
-
* parser.parse -> (true|false)
|
71
|
-
*
|
72
|
-
* Parse the input XML, generating callbacks to the object
|
73
|
-
* registered via the +callbacks+ attributesibute.
|
74
|
-
*/
|
75
|
-
static VALUE rxml_sax_parser_parse(VALUE self)
|
76
|
-
{
|
77
|
-
VALUE context = rb_ivar_get(self, CONTEXT_ATTR);
|
78
|
-
xmlParserCtxtPtr ctxt;
|
79
|
-
Data_Get_Struct(context, xmlParserCtxt, ctxt);
|
80
|
-
|
81
|
-
ctxt->sax2 = 1;
|
82
|
-
ctxt->userData = (void*)rb_ivar_get(self, CALLBACKS_ATTR);
|
83
|
-
memcpy(ctxt->sax, &rxml_sax_handler, sizeof(rxml_sax_handler));
|
84
|
-
|
85
|
-
int status = xmlParseDocument(ctxt);
|
86
|
-
|
87
|
-
/* Now check the parsing result*/
|
88
|
-
if (status == -1 || !ctxt->wellFormed)
|
89
|
-
{
|
90
|
-
rxml_raise(&ctxt->lastError);
|
91
|
-
}
|
92
|
-
return Qtrue;
|
93
|
-
}
|
94
|
-
|
95
|
-
void rxml_init_sax_parser(void)
|
96
|
-
{
|
97
|
-
/* SaxParser */
|
98
|
-
cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject);
|
99
|
-
|
100
|
-
/* Atributes */
|
101
|
-
CALLBACKS_ATTR = rb_intern("@callbacks");
|
102
|
-
CONTEXT_ATTR = rb_intern("@context");
|
103
|
-
rb_define_attr(cXMLSaxParser, "callbacks", 1, 1);
|
104
|
-
|
105
|
-
/* Instance Methods */
|
106
|
-
rb_define_method(cXMLSaxParser, "initialize", rxml_sax_parser_initialize, -1);
|
107
|
-
rb_define_method(cXMLSaxParser, "parse", rxml_sax_parser_parse, 0);
|
108
|
-
}
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#include "ruby_libxml.h"
|
4
|
+
#include "ruby_xml_sax_parser.h"
|
5
|
+
|
6
|
+
/*
|
7
|
+
* Document-class: LibXML::XML::SaxParser
|
8
|
+
*
|
9
|
+
* XML::SaxParser provides a callback based API for parsing documents,
|
10
|
+
* in contrast to XML::Parser's tree based API and XML::Reader's stream
|
11
|
+
* based API.
|
12
|
+
*
|
13
|
+
* The XML::SaxParser API is fairly complex, not well standardized,
|
14
|
+
* and does not directly support validation making entity, namespace and
|
15
|
+
* base processing relatively hard.
|
16
|
+
*
|
17
|
+
* To use the XML::SaxParser, register a callback class via the
|
18
|
+
* XML::SaxParser#callbacks=. It is easiest to include the
|
19
|
+
* XML::SaxParser::Callbacks module in your class and override
|
20
|
+
* the methods as needed.
|
21
|
+
*
|
22
|
+
* Basic example:
|
23
|
+
*
|
24
|
+
* class MyCallbacks
|
25
|
+
* include XML::SaxParser::Callbacks
|
26
|
+
* def on_start_element(element, attributes)
|
27
|
+
* puts #Element started: #{element}"
|
28
|
+
* end
|
29
|
+
* end
|
30
|
+
*
|
31
|
+
* parser = XML::SaxParser.string(my_string)
|
32
|
+
* parser.callbacks = MyCallbacks.new
|
33
|
+
* parser.parse
|
34
|
+
*
|
35
|
+
* You can also parse strings (see XML::SaxParser.string) and
|
36
|
+
* io objects (see XML::SaxParser.io).
|
37
|
+
*/
|
38
|
+
|
39
|
+
VALUE cXMLSaxParser;
|
40
|
+
static ID CALLBACKS_ATTR;
|
41
|
+
static ID CONTEXT_ATTR;
|
42
|
+
|
43
|
+
|
44
|
+
/* ====== Parser =========== */
|
45
|
+
|
46
|
+
/*
|
47
|
+
* call-seq:
|
48
|
+
* parser.initialize(context) -> XML::Parser
|
49
|
+
*
|
50
|
+
* Creates a new XML::Parser from the specified
|
51
|
+
* XML::Parser::Context.
|
52
|
+
*/
|
53
|
+
static VALUE rxml_sax_parser_initialize(int argc, VALUE *argv, VALUE self)
|
54
|
+
{
|
55
|
+
VALUE context = Qnil;
|
56
|
+
|
57
|
+
rb_scan_args(argc, argv, "01", &context);
|
58
|
+
|
59
|
+
if (context == Qnil)
|
60
|
+
{
|
61
|
+
rb_raise(rb_eArgError, "An instance of a XML::Parser::Context must be passed to XML::SaxParser.new");
|
62
|
+
}
|
63
|
+
|
64
|
+
rb_ivar_set(self, CONTEXT_ATTR, context);
|
65
|
+
return self;
|
66
|
+
}
|
67
|
+
|
68
|
+
/*
|
69
|
+
* call-seq:
|
70
|
+
* parser.parse -> (true|false)
|
71
|
+
*
|
72
|
+
* Parse the input XML, generating callbacks to the object
|
73
|
+
* registered via the +callbacks+ attributesibute.
|
74
|
+
*/
|
75
|
+
static VALUE rxml_sax_parser_parse(VALUE self)
|
76
|
+
{
|
77
|
+
VALUE context = rb_ivar_get(self, CONTEXT_ATTR);
|
78
|
+
xmlParserCtxtPtr ctxt;
|
79
|
+
Data_Get_Struct(context, xmlParserCtxt, ctxt);
|
80
|
+
|
81
|
+
ctxt->sax2 = 1;
|
82
|
+
ctxt->userData = (void*)rb_ivar_get(self, CALLBACKS_ATTR);
|
83
|
+
memcpy(ctxt->sax, &rxml_sax_handler, sizeof(rxml_sax_handler));
|
84
|
+
|
85
|
+
int status = xmlParseDocument(ctxt);
|
86
|
+
|
87
|
+
/* Now check the parsing result*/
|
88
|
+
if (status == -1 || !ctxt->wellFormed)
|
89
|
+
{
|
90
|
+
rxml_raise(&ctxt->lastError);
|
91
|
+
}
|
92
|
+
return Qtrue;
|
93
|
+
}
|
94
|
+
|
95
|
+
void rxml_init_sax_parser(void)
|
96
|
+
{
|
97
|
+
/* SaxParser */
|
98
|
+
cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject);
|
99
|
+
|
100
|
+
/* Atributes */
|
101
|
+
CALLBACKS_ATTR = rb_intern("@callbacks");
|
102
|
+
CONTEXT_ATTR = rb_intern("@context");
|
103
|
+
rb_define_attr(cXMLSaxParser, "callbacks", 1, 1);
|
104
|
+
|
105
|
+
/* Instance Methods */
|
106
|
+
rb_define_method(cXMLSaxParser, "initialize", rxml_sax_parser_initialize, -1);
|
107
|
+
rb_define_method(cXMLSaxParser, "parse", rxml_sax_parser_parse, 0);
|
108
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
/* Don't nuke this block! It is used for automatically updating the
|
2
|
-
* versions below. VERSION = string formatting, VERNUM = numbered
|
3
|
-
* version for inline testing: increment both or none at all.*/
|
4
|
-
#define RUBY_LIBXML_VERSION "5.0.
|
5
|
-
#define RUBY_LIBXML_VERNUM
|
6
|
-
#define RUBY_LIBXML_VER_MAJ 5
|
7
|
-
#define RUBY_LIBXML_VER_MIN 0
|
8
|
-
#define RUBY_LIBXML_VER_MIC
|
9
|
-
#define RUBY_LIBXML_VER_PATCH 0
|
1
|
+
/* Don't nuke this block! It is used for automatically updating the
|
2
|
+
* versions below. VERSION = string formatting, VERNUM = numbered
|
3
|
+
* version for inline testing: increment both or none at all.*/
|
4
|
+
#define RUBY_LIBXML_VERSION "5.0.5"
|
5
|
+
#define RUBY_LIBXML_VERNUM 505
|
6
|
+
#define RUBY_LIBXML_VER_MAJ 5
|
7
|
+
#define RUBY_LIBXML_VER_MIN 0
|
8
|
+
#define RUBY_LIBXML_VER_MIC 5
|
9
|
+
#define RUBY_LIBXML_VER_PATCH 0
|
data/lib/libxml/attr.rb
CHANGED
@@ -1,123 +1,123 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module LibXML
|
4
|
-
module XML
|
5
|
-
class Attr
|
6
|
-
include Enumerable
|
7
|
-
|
8
|
-
# call-seq:
|
9
|
-
# attr.child? -> (true|false)
|
10
|
-
#
|
11
|
-
# Returns whether this attribute has child attributes.
|
12
|
-
#
|
13
|
-
def child?
|
14
|
-
not self.children.nil?
|
15
|
-
end
|
16
|
-
|
17
|
-
# call-seq:
|
18
|
-
# attr.doc? -> (true|false)
|
19
|
-
#
|
20
|
-
# Determine whether this attribute is associated with an
|
21
|
-
# XML::Document.
|
22
|
-
def doc?
|
23
|
-
not self.doc.nil?
|
24
|
-
end
|
25
|
-
|
26
|
-
# call-seq:
|
27
|
-
# attr.last? -> (true|false)
|
28
|
-
#
|
29
|
-
# Determine whether this is the last attribute.
|
30
|
-
def last?
|
31
|
-
self.last.nil?
|
32
|
-
end
|
33
|
-
|
34
|
-
# call-seq:
|
35
|
-
# attr.next? -> (true|false)
|
36
|
-
#
|
37
|
-
# Determine whether there is a next attribute.
|
38
|
-
def next?
|
39
|
-
not self.next.nil?
|
40
|
-
end
|
41
|
-
|
42
|
-
# call-seq:
|
43
|
-
# attr.ns? -> (true|false)
|
44
|
-
#
|
45
|
-
# Determine whether this attribute has an associated
|
46
|
-
# namespace.
|
47
|
-
def ns?
|
48
|
-
not self.ns.nil?
|
49
|
-
end
|
50
|
-
|
51
|
-
# call-seq:
|
52
|
-
# attr.namespacess -> XML::Namespaces
|
53
|
-
#
|
54
|
-
# Returns this node's XML::Namespaces object,
|
55
|
-
# which is used to access the namespaces
|
56
|
-
# associated with this node.
|
57
|
-
def namespaces
|
58
|
-
@namespaces ||= XML::Namespaces.new(self)
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
# call-seq:
|
63
|
-
# attr.parent? -> (true|false)
|
64
|
-
#
|
65
|
-
# Determine whether this attribute has a parent.
|
66
|
-
def parent?
|
67
|
-
not self.parent.nil?
|
68
|
-
end
|
69
|
-
|
70
|
-
# call-seq:
|
71
|
-
# attr.prev? -> (true|false)
|
72
|
-
#
|
73
|
-
# Determine whether there is a previous attribute.
|
74
|
-
def prev?
|
75
|
-
not self.prev.nil?
|
76
|
-
end
|
77
|
-
|
78
|
-
# Returns this node's type name
|
79
|
-
def node_type_name
|
80
|
-
if node_type == Node::ATTRIBUTE_NODE
|
81
|
-
'attribute'
|
82
|
-
else
|
83
|
-
raise(UnknownType, "Unknown node type: %n", node.node_type);
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# Iterates nodes and attributes
|
88
|
-
def siblings(node, &blk)
|
89
|
-
if n = node
|
90
|
-
loop do
|
91
|
-
blk.call(n)
|
92
|
-
break unless n = n.next
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def each_sibling(&blk)
|
98
|
-
siblings(self,&blk)
|
99
|
-
end
|
100
|
-
|
101
|
-
alias :each_attr :each_sibling
|
102
|
-
alias :each :each_sibling
|
103
|
-
|
104
|
-
def to_h
|
105
|
-
inject({}) do |h,a|
|
106
|
-
h[a.name] = a.value
|
107
|
-
h
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def to_a
|
112
|
-
inject([]) do |ary,a|
|
113
|
-
ary << [a.name, a.value]
|
114
|
-
ary
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def to_s
|
119
|
-
"#{name} = #{value}"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module LibXML
|
4
|
+
module XML
|
5
|
+
class Attr
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
# call-seq:
|
9
|
+
# attr.child? -> (true|false)
|
10
|
+
#
|
11
|
+
# Returns whether this attribute has child attributes.
|
12
|
+
#
|
13
|
+
def child?
|
14
|
+
not self.children.nil?
|
15
|
+
end
|
16
|
+
|
17
|
+
# call-seq:
|
18
|
+
# attr.doc? -> (true|false)
|
19
|
+
#
|
20
|
+
# Determine whether this attribute is associated with an
|
21
|
+
# XML::Document.
|
22
|
+
def doc?
|
23
|
+
not self.doc.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
# call-seq:
|
27
|
+
# attr.last? -> (true|false)
|
28
|
+
#
|
29
|
+
# Determine whether this is the last attribute.
|
30
|
+
def last?
|
31
|
+
self.last.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
# call-seq:
|
35
|
+
# attr.next? -> (true|false)
|
36
|
+
#
|
37
|
+
# Determine whether there is a next attribute.
|
38
|
+
def next?
|
39
|
+
not self.next.nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
# call-seq:
|
43
|
+
# attr.ns? -> (true|false)
|
44
|
+
#
|
45
|
+
# Determine whether this attribute has an associated
|
46
|
+
# namespace.
|
47
|
+
def ns?
|
48
|
+
not self.ns.nil?
|
49
|
+
end
|
50
|
+
|
51
|
+
# call-seq:
|
52
|
+
# attr.namespacess -> XML::Namespaces
|
53
|
+
#
|
54
|
+
# Returns this node's XML::Namespaces object,
|
55
|
+
# which is used to access the namespaces
|
56
|
+
# associated with this node.
|
57
|
+
def namespaces
|
58
|
+
@namespaces ||= XML::Namespaces.new(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# call-seq:
|
63
|
+
# attr.parent? -> (true|false)
|
64
|
+
#
|
65
|
+
# Determine whether this attribute has a parent.
|
66
|
+
def parent?
|
67
|
+
not self.parent.nil?
|
68
|
+
end
|
69
|
+
|
70
|
+
# call-seq:
|
71
|
+
# attr.prev? -> (true|false)
|
72
|
+
#
|
73
|
+
# Determine whether there is a previous attribute.
|
74
|
+
def prev?
|
75
|
+
not self.prev.nil?
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns this node's type name
|
79
|
+
def node_type_name
|
80
|
+
if node_type == Node::ATTRIBUTE_NODE
|
81
|
+
'attribute'
|
82
|
+
else
|
83
|
+
raise(UnknownType, "Unknown node type: %n", node.node_type);
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Iterates nodes and attributes
|
88
|
+
def siblings(node, &blk)
|
89
|
+
if n = node
|
90
|
+
loop do
|
91
|
+
blk.call(n)
|
92
|
+
break unless n = n.next
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def each_sibling(&blk)
|
98
|
+
siblings(self,&blk)
|
99
|
+
end
|
100
|
+
|
101
|
+
alias :each_attr :each_sibling
|
102
|
+
alias :each :each_sibling
|
103
|
+
|
104
|
+
def to_h
|
105
|
+
inject({}) do |h,a|
|
106
|
+
h[a.name] = a.value
|
107
|
+
h
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def to_a
|
112
|
+
inject([]) do |ary,a|
|
113
|
+
ary << [a.name, a.value]
|
114
|
+
ary
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def to_s
|
119
|
+
"#{name} = #{value}"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
123
|
end
|
data/lib/libxml/attr_decl.rb
CHANGED
@@ -1,80 +1,80 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module LibXML
|
4
|
-
module XML
|
5
|
-
class AttrDecl
|
6
|
-
include Enumerable
|
7
|
-
|
8
|
-
# call-seq:
|
9
|
-
# attr_decl.child -> nil
|
10
|
-
#
|
11
|
-
# Obtain this attribute declaration's child attribute(s).
|
12
|
-
# It will always be nil.
|
13
|
-
def child
|
14
|
-
nil
|
15
|
-
end
|
16
|
-
|
17
|
-
# call-seq:
|
18
|
-
# attr_decl.child? -> (true|false)
|
19
|
-
#
|
20
|
-
# Returns whether this attribute declaration has child attributes.
|
21
|
-
#
|
22
|
-
def child?
|
23
|
-
not self.children.nil?
|
24
|
-
end
|
25
|
-
|
26
|
-
# call-seq:
|
27
|
-
# attr_decl.doc? -> (true|false)
|
28
|
-
#
|
29
|
-
# Determine whether this attribute declaration is associated with an
|
30
|
-
# XML::Document.
|
31
|
-
def doc?
|
32
|
-
not self.doc.nil?
|
33
|
-
end
|
34
|
-
|
35
|
-
# call-seq:
|
36
|
-
# attr_decl.next? -> (true|false)
|
37
|
-
#
|
38
|
-
# Determine whether there is a next attribute declaration.
|
39
|
-
def next?
|
40
|
-
not self.next.nil?
|
41
|
-
end
|
42
|
-
|
43
|
-
# call-seq:
|
44
|
-
# attr_decl.parent? -> (true|false)
|
45
|
-
#
|
46
|
-
# Determine whether this attribute declaration has a parent .
|
47
|
-
def parent?
|
48
|
-
not self.parent.nil?
|
49
|
-
end
|
50
|
-
|
51
|
-
# call-seq:
|
52
|
-
# attr_decl.prev? -> (true|false)
|
53
|
-
#
|
54
|
-
# Determine whether there is a previous attribute declaration.
|
55
|
-
def prev?
|
56
|
-
not self.prev.nil?
|
57
|
-
end
|
58
|
-
|
59
|
-
# call-seq:
|
60
|
-
# attr_decl.node_type_name -> 'attribute declaration'
|
61
|
-
#
|
62
|
-
# Returns this attribute declaration's node type name.
|
63
|
-
def node_type_name
|
64
|
-
if node_type == Node::ATTRIBUTE_DECL
|
65
|
-
'attribute declaration'
|
66
|
-
else
|
67
|
-
raise(UnknownType, "Unknown node type: %n", node.node_type);
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# call-seq:
|
72
|
-
# attr_decl.to_s -> string
|
73
|
-
#
|
74
|
-
# Returns a string representation of this attribute declaration.
|
75
|
-
def to_s
|
76
|
-
"#{name} = #{value}"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module LibXML
|
4
|
+
module XML
|
5
|
+
class AttrDecl
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
# call-seq:
|
9
|
+
# attr_decl.child -> nil
|
10
|
+
#
|
11
|
+
# Obtain this attribute declaration's child attribute(s).
|
12
|
+
# It will always be nil.
|
13
|
+
def child
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
# call-seq:
|
18
|
+
# attr_decl.child? -> (true|false)
|
19
|
+
#
|
20
|
+
# Returns whether this attribute declaration has child attributes.
|
21
|
+
#
|
22
|
+
def child?
|
23
|
+
not self.children.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
# call-seq:
|
27
|
+
# attr_decl.doc? -> (true|false)
|
28
|
+
#
|
29
|
+
# Determine whether this attribute declaration is associated with an
|
30
|
+
# XML::Document.
|
31
|
+
def doc?
|
32
|
+
not self.doc.nil?
|
33
|
+
end
|
34
|
+
|
35
|
+
# call-seq:
|
36
|
+
# attr_decl.next? -> (true|false)
|
37
|
+
#
|
38
|
+
# Determine whether there is a next attribute declaration.
|
39
|
+
def next?
|
40
|
+
not self.next.nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
# call-seq:
|
44
|
+
# attr_decl.parent? -> (true|false)
|
45
|
+
#
|
46
|
+
# Determine whether this attribute declaration has a parent .
|
47
|
+
def parent?
|
48
|
+
not self.parent.nil?
|
49
|
+
end
|
50
|
+
|
51
|
+
# call-seq:
|
52
|
+
# attr_decl.prev? -> (true|false)
|
53
|
+
#
|
54
|
+
# Determine whether there is a previous attribute declaration.
|
55
|
+
def prev?
|
56
|
+
not self.prev.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
# call-seq:
|
60
|
+
# attr_decl.node_type_name -> 'attribute declaration'
|
61
|
+
#
|
62
|
+
# Returns this attribute declaration's node type name.
|
63
|
+
def node_type_name
|
64
|
+
if node_type == Node::ATTRIBUTE_DECL
|
65
|
+
'attribute declaration'
|
66
|
+
else
|
67
|
+
raise(UnknownType, "Unknown node type: %n", node.node_type);
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# call-seq:
|
72
|
+
# attr_decl.to_s -> string
|
73
|
+
#
|
74
|
+
# Returns a string representation of this attribute declaration.
|
75
|
+
def to_s
|
76
|
+
"#{name} = #{value}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/libxml/attributes.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module LibXML
|
4
|
-
module XML
|
5
|
-
class Attributes
|
6
|
-
def to_h
|
7
|
-
inject({}) do |hash, attr|
|
8
|
-
hash[attr.name] = attr.value
|
9
|
-
hash
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module LibXML
|
4
|
+
module XML
|
5
|
+
class Attributes
|
6
|
+
def to_h
|
7
|
+
inject({}) do |hash, attr|
|
8
|
+
hash[attr.name] = attr.value
|
9
|
+
hash
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
14
|
end
|