libxml-ruby-r19mingw 1.1.4

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.
Files changed (163) hide show
  1. data/CHANGES +481 -0
  2. data/LICENSE +22 -0
  3. data/README +161 -0
  4. data/Rakefile +182 -0
  5. data/doc/css/normal.css +182 -0
  6. data/doc/img/raze-tiny.png +0 -0
  7. data/doc/img/red-cube.jpg +0 -0
  8. data/doc/img/xml-ruby.png +0 -0
  9. data/doc/index.xml +43 -0
  10. data/doc/install.xml +77 -0
  11. data/doc/layout.rhtml +38 -0
  12. data/doc/layout.xsl +67 -0
  13. data/doc/license.xml +32 -0
  14. data/doc/log/changelog.xml +1324 -0
  15. data/doc/log/changelog.xsl +42 -0
  16. data/ext/libxml/Makefile +187 -0
  17. data/ext/libxml/extconf.h +4 -0
  18. data/ext/libxml/extconf.rb +122 -0
  19. data/ext/libxml/libxml.c +77 -0
  20. data/ext/libxml/mkmf.log +880 -0
  21. data/ext/libxml/ruby_libxml.h +93 -0
  22. data/ext/libxml/ruby_xml.c +893 -0
  23. data/ext/libxml/ruby_xml.h +10 -0
  24. data/ext/libxml/ruby_xml_attr.c +352 -0
  25. data/ext/libxml/ruby_xml_attr.h +14 -0
  26. data/ext/libxml/ruby_xml_attr_decl.c +171 -0
  27. data/ext/libxml/ruby_xml_attr_decl.h +13 -0
  28. data/ext/libxml/ruby_xml_attributes.c +277 -0
  29. data/ext/libxml/ruby_xml_attributes.h +17 -0
  30. data/ext/libxml/ruby_xml_cbg.c +86 -0
  31. data/ext/libxml/ruby_xml_document.c +936 -0
  32. data/ext/libxml/ruby_xml_document.h +17 -0
  33. data/ext/libxml/ruby_xml_dtd.c +257 -0
  34. data/ext/libxml/ruby_xml_dtd.h +9 -0
  35. data/ext/libxml/ruby_xml_encoding.c +134 -0
  36. data/ext/libxml/ruby_xml_encoding.h +12 -0
  37. data/ext/libxml/ruby_xml_error.c +1004 -0
  38. data/ext/libxml/ruby_xml_error.h +14 -0
  39. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  40. data/ext/libxml/ruby_xml_html_parser.h +12 -0
  41. data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
  42. data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
  43. data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
  44. data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
  45. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  46. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  47. data/ext/libxml/ruby_xml_io.c +30 -0
  48. data/ext/libxml/ruby_xml_io.h +9 -0
  49. data/ext/libxml/ruby_xml_namespace.c +170 -0
  50. data/ext/libxml/ruby_xml_namespace.h +12 -0
  51. data/ext/libxml/ruby_xml_namespaces.c +295 -0
  52. data/ext/libxml/ruby_xml_namespaces.h +11 -0
  53. data/ext/libxml/ruby_xml_node.c +1386 -0
  54. data/ext/libxml/ruby_xml_node.h +13 -0
  55. data/ext/libxml/ruby_xml_parser.c +94 -0
  56. data/ext/libxml/ruby_xml_parser.h +14 -0
  57. data/ext/libxml/ruby_xml_parser_context.c +982 -0
  58. data/ext/libxml/ruby_xml_parser_context.h +12 -0
  59. data/ext/libxml/ruby_xml_parser_options.c +68 -0
  60. data/ext/libxml/ruby_xml_parser_options.h +14 -0
  61. data/ext/libxml/ruby_xml_reader.c +1002 -0
  62. data/ext/libxml/ruby_xml_reader.h +14 -0
  63. data/ext/libxml/ruby_xml_relaxng.c +111 -0
  64. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  65. data/ext/libxml/ruby_xml_sax2_handler.c +322 -0
  66. data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
  67. data/ext/libxml/ruby_xml_sax_parser.c +137 -0
  68. data/ext/libxml/ruby_xml_sax_parser.h +12 -0
  69. data/ext/libxml/ruby_xml_schema.c +159 -0
  70. data/ext/libxml/ruby_xml_schema.h +11 -0
  71. data/ext/libxml/ruby_xml_version.h +9 -0
  72. data/ext/libxml/ruby_xml_xinclude.c +18 -0
  73. data/ext/libxml/ruby_xml_xinclude.h +13 -0
  74. data/ext/libxml/ruby_xml_xpath.c +107 -0
  75. data/ext/libxml/ruby_xml_xpath.h +12 -0
  76. data/ext/libxml/ruby_xml_xpath_context.c +387 -0
  77. data/ext/libxml/ruby_xml_xpath_context.h +11 -0
  78. data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
  79. data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
  80. data/ext/libxml/ruby_xml_xpath_object.c +336 -0
  81. data/ext/libxml/ruby_xml_xpath_object.h +19 -0
  82. data/ext/libxml/ruby_xml_xpointer.c +101 -0
  83. data/ext/libxml/ruby_xml_xpointer.h +13 -0
  84. data/ext/mingw/Rakefile +34 -0
  85. data/ext/mingw/build.rake +41 -0
  86. data/ext/vc/libxml_ruby.sln +26 -0
  87. data/lib/libxml.rb +30 -0
  88. data/lib/libxml/attr.rb +111 -0
  89. data/lib/libxml/attr_decl.rb +78 -0
  90. data/lib/libxml/attributes.rb +12 -0
  91. data/lib/libxml/document.rb +190 -0
  92. data/lib/libxml/error.rb +88 -0
  93. data/lib/libxml/hpricot.rb +76 -0
  94. data/lib/libxml/html_parser.rb +94 -0
  95. data/lib/libxml/namespace.rb +60 -0
  96. data/lib/libxml/namespaces.rb +36 -0
  97. data/lib/libxml/node.rb +385 -0
  98. data/lib/libxml/ns.rb +20 -0
  99. data/lib/libxml/parser.rb +365 -0
  100. data/lib/libxml/properties.rb +21 -0
  101. data/lib/libxml/reader.rb +27 -0
  102. data/lib/libxml/sax_callbacks.rb +178 -0
  103. data/lib/libxml/sax_parser.rb +56 -0
  104. data/lib/libxml/tree.rb +27 -0
  105. data/lib/libxml/xpath_object.rb +14 -0
  106. data/lib/xml.rb +14 -0
  107. data/lib/xml/libxml.rb +8 -0
  108. data/setup.rb +1585 -0
  109. data/test/etc_doc_to_s.rb +19 -0
  110. data/test/ets_doc_file.rb +15 -0
  111. data/test/ets_doc_to_s.rb +21 -0
  112. data/test/ets_gpx.rb +26 -0
  113. data/test/ets_node_gc.rb +21 -0
  114. data/test/ets_test.xml +2 -0
  115. data/test/ets_tsr.rb +9 -0
  116. data/test/model/atom.xml +13 -0
  117. data/test/model/bands.xml +5 -0
  118. data/test/model/books.xml +146 -0
  119. data/test/model/merge_bug_data.xml +58 -0
  120. data/test/model/ruby-lang.html +238 -0
  121. data/test/model/rubynet.xml +79 -0
  122. data/test/model/rubynet_project +1 -0
  123. data/test/model/shiporder.rnc +28 -0
  124. data/test/model/shiporder.rng +86 -0
  125. data/test/model/shiporder.xml +23 -0
  126. data/test/model/shiporder.xsd +31 -0
  127. data/test/model/soap.xml +27 -0
  128. data/test/model/xinclude.xml +5 -0
  129. data/test/tc_attr.rb +170 -0
  130. data/test/tc_attr_decl.rb +131 -0
  131. data/test/tc_attributes.rb +133 -0
  132. data/test/tc_deprecated_require.rb +11 -0
  133. data/test/tc_document.rb +113 -0
  134. data/test/tc_document_write.rb +118 -0
  135. data/test/tc_dtd.rb +123 -0
  136. data/test/tc_error.rb +136 -0
  137. data/test/tc_html_parser.rb +138 -0
  138. data/test/tc_namespace.rb +59 -0
  139. data/test/tc_namespaces.rb +174 -0
  140. data/test/tc_node.rb +181 -0
  141. data/test/tc_node_cdata.rb +49 -0
  142. data/test/tc_node_comment.rb +30 -0
  143. data/test/tc_node_copy.rb +40 -0
  144. data/test/tc_node_edit.rb +158 -0
  145. data/test/tc_node_text.rb +69 -0
  146. data/test/tc_node_write.rb +83 -0
  147. data/test/tc_node_xlink.rb +26 -0
  148. data/test/tc_parser.rb +330 -0
  149. data/test/tc_parser_context.rb +186 -0
  150. data/test/tc_properties.rb +36 -0
  151. data/test/tc_reader.rb +284 -0
  152. data/test/tc_relaxng.rb +51 -0
  153. data/test/tc_sax_parser.rb +274 -0
  154. data/test/tc_schema.rb +51 -0
  155. data/test/tc_traversal.rb +220 -0
  156. data/test/tc_xinclude.rb +19 -0
  157. data/test/tc_xml.rb +224 -0
  158. data/test/tc_xpath.rb +193 -0
  159. data/test/tc_xpath_context.rb +78 -0
  160. data/test/tc_xpath_expression.rb +35 -0
  161. data/test/tc_xpointer.rb +72 -0
  162. data/test/test_suite.rb +33 -0
  163. metadata +260 -0
@@ -0,0 +1,88 @@
1
+ module LibXML
2
+ module XML
3
+ class Error
4
+ # Verbose error handler
5
+ VERBOSE_HANDLER = lambda do |error|
6
+ STDERR << error.to_s << "\n"
7
+ STDERR.flush
8
+ end
9
+
10
+ # Quiet error handler
11
+ QUIET_HANDLER = lambda do |error|
12
+ end
13
+
14
+ def ==(other)
15
+ eql?(other)
16
+ end
17
+
18
+ def eql?(other)
19
+ self.code == other.code and
20
+ self.domain == other.domain and
21
+ self.message == other.message and
22
+ self.level == other.level and
23
+ self.file == other.file and
24
+ self.line == other.line and
25
+ self.str1 == other.str1 and
26
+ self.str2 == other.str2 and
27
+ self.str3 == other.str3 and
28
+ self.int1 == other.int1 and
29
+ self.int2 == other.int2 and
30
+ self.ctxt == other.ctxt and
31
+ self.node == other.node
32
+ end
33
+
34
+ def level_to_s
35
+ case self.level
36
+ when NONE
37
+ ''
38
+ when WARNING
39
+ 'Warning:'
40
+ when ERROR
41
+ 'Error:'
42
+ when FATAL
43
+ 'Fatal error:'
44
+ end
45
+ end
46
+
47
+ def domain_to_s
48
+ const_map = Hash.new
49
+ domains = self.class.constants.grep(/XML_FROM/)
50
+ domains.each do |domain|
51
+ human_name = domain.gsub(/XML_FROM_/, '')
52
+ const_map[self.class.const_get(domain)] = human_name
53
+ end
54
+
55
+ const_map[self.domain]
56
+ end
57
+
58
+ def code_to_s
59
+ const_map = Hash.new
60
+ codes = self.class.constants -
61
+ self.class.constants.grep(/XML_FROM/) -
62
+ ["XML_ERR_NONE", "XML_ERR_WARNING", "XML_ERR_ERROR", "XML_ERR_FATAL"]
63
+
64
+
65
+ codes.each do |code|
66
+ human_name = code.gsub(/XML_ERR_/, '')
67
+ const_map[self.class.const_get(code)] = human_name
68
+ end
69
+
70
+ const_map[self.code]
71
+ end
72
+
73
+ def to_s
74
+ msg = super
75
+ msg = msg ? msg.strip: ''
76
+
77
+ if self.line
78
+ sprintf("%s %s at %s:%d.", self.level_to_s, msg,
79
+ self.file, self.line)
80
+ else
81
+ sprintf("%s %s.", self.level_to_s, msg)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
@@ -0,0 +1,76 @@
1
+ ## Provide hpricot API for libxml. Provided by Michael Guterl,
2
+ ## inspired by http://thebogles.com/blog/an-hpricot-style-interface-to-libxml
3
+ #
4
+ #class String
5
+ # def to_libxml_doc
6
+ # xp = XML::Parser.new
7
+ # xp.string = self
8
+ # xp.parse
9
+ # end
10
+ #end
11
+ #
12
+ #module LibXML
13
+ # module XML
14
+ # class Document
15
+ # alias :search :find
16
+ # end
17
+ #
18
+ # class Node
19
+ # # find the child node with the given xpath
20
+ # def at(xpath)
21
+ # self.find_first(xpath)
22
+ # end
23
+ #
24
+ # # find the array of child nodes matching the given xpath
25
+ # def search(xpath)
26
+ # results = self.find(xpath).to_a
27
+ # if block_given?
28
+ # results.each do |result|
29
+ # yield result
30
+ # end
31
+ # end
32
+ # return results
33
+ # end
34
+ #
35
+ # def /(xpath)
36
+ # search(xpath)
37
+ # end
38
+ #
39
+ # # return the inner contents of this node as a string
40
+ # def inner_xml
41
+ # child.to_s
42
+ # end
43
+ #
44
+ # # alias for inner_xml
45
+ # def inner_html
46
+ # inner_xml
47
+ # end
48
+ #
49
+ # # return this node and its contents as an xml string
50
+ # def to_xml
51
+ # self.to_s
52
+ # end
53
+ #
54
+ # # alias for path
55
+ # def xpath
56
+ # self.path
57
+ # end
58
+ #
59
+ # def find_with_default_ns(xpath_expr, namespace=nil)
60
+ # find_base(xpath_expr, namespace || default_namespaces)
61
+ # end
62
+ #
63
+ # def find_first_with_default_ns(xpath_expr, namespace=nil)
64
+ # find_first_base(xpath_expr, namespace || default_namespaces)
65
+ # end
66
+ #
67
+ ## alias_method :find_base, :find unless method_defined?(:find_base)
68
+ ## alias_method :find, :find_with_default_ns
69
+ ## alias_method :find_first_base, :find_first unless method_defined?(:find_first_base)
70
+ ## alias_method :find_first, :find_first_with_default_ns
71
+ ## alias :child? :first?
72
+ ## alias :children? :first?
73
+ ## alias :child :first
74
+ # end
75
+ # end
76
+ #end
@@ -0,0 +1,94 @@
1
+ module LibXML
2
+ module XML
3
+ class HTMLParser
4
+ # call-seq:
5
+ # XML::HTMLParser.file(path) -> XML::HTMLParser
6
+ # XML::HTMLParser.file(path, :encoding => XML::Encoding::UTF_8,
7
+ # :options => XML::HTMLParser::Options::NOENT) -> XML::HTMLParser
8
+ #
9
+ # Creates a new parser by parsing the specified file or uri.
10
+ #
11
+ # You may provide an optional hash table to control how the
12
+ # parsing is performed. Valid options are:
13
+ #
14
+ # encoding - The document encoding, defaults to nil. Valid values
15
+ # are the encoding constants defined on XML::Encoding.
16
+ # options - Parser options. Valid values are the constants defined on
17
+ # XML::HTMLParser::Options. Mutliple options can be combined
18
+ # by using Bitwise OR (|).
19
+ def self.file(path, options = {})
20
+ context = XML::HTMLParser::Context.file(path)
21
+ context.encoding = options[:encoding] if options[:encoding]
22
+ context.options = options[:options] if options[:options]
23
+ self.new(context)
24
+ end
25
+
26
+ # call-seq:
27
+ # XML::HTMLParser.io(io) -> XML::HTMLParser
28
+ # XML::HTMLParser.io(io, :encoding => XML::Encoding::UTF_8,
29
+ # :options => XML::HTMLParser::Options::NOENT
30
+ # :base_uri="http://libxml.org") -> XML::HTMLParser
31
+ #
32
+ # Creates a new reader by parsing the specified io object.
33
+ #
34
+ # Parameters:
35
+ #
36
+ # io - io object that contains the xml to parser
37
+ # base_uri - The base url for the parsed document.
38
+ # encoding - The document encoding, defaults to nil. Valid values
39
+ # are the encoding constants defined on XML::Encoding.
40
+ # options - Parser options. Valid values are the constants defined on
41
+ # XML::HTMLParser::Options. Mutliple options can be combined
42
+ # by using Bitwise OR (|).
43
+ def self.io(io, options = {})
44
+ context = XML::HTMLParser::Context.io(io)
45
+ context.base_uri = options[:base_uri] if options[:base_uri]
46
+ context.encoding = options[:encoding] if options[:encoding]
47
+ context.options = options[:options] if options[:options]
48
+ self.new(context)
49
+ end
50
+
51
+ # call-seq:
52
+ # XML::HTMLParser.string(string)
53
+ # XML::HTMLParser.string(string, :encoding => XML::Encoding::UTF_8,
54
+ # :options => XML::HTMLParser::Options::NOENT
55
+ # :base_uri="http://libxml.org") -> XML::HTMLParser
56
+ #
57
+ # Creates a new parser by parsing the specified string.
58
+ #
59
+ # You may provide an optional hash table to control how the
60
+ # parsing is performed. Valid options are:
61
+ #
62
+ # base_uri - The base url for the parsed document.
63
+ # encoding - The document encoding, defaults to nil. Valid values
64
+ # are the encoding constants defined on XML::Encoding.
65
+ # options - Parser options. Valid values are the constants defined on
66
+ # XML::HTMLParser::Options. Mutliple options can be combined
67
+ # by using Bitwise OR (|).
68
+ def self.string(string, options = {})
69
+ context = XML::HTMLParser::Context.string(string)
70
+ context.base_uri = options[:base_uri] if options[:base_uri]
71
+ context.encoding = options[:encoding] if options[:encoding]
72
+ context.options = options[:options] if options[:options]
73
+ self.new(context)
74
+ end
75
+
76
+ # :enddoc:
77
+
78
+ def file=(value)
79
+ warn("XML::HTMLParser#file is deprecated. Use XML::HTMLParser.file instead")
80
+ @context = XML::HTMLParser::Context.file(value)
81
+ end
82
+
83
+ def io=(value)
84
+ warn("XML::HTMLParser#io is deprecated. Use XML::HTMLParser.io instead")
85
+ @context = XML::HTMLParser::Context.io(value)
86
+ end
87
+
88
+ def string=(value)
89
+ warn("XML::HTMLParser#string is deprecated. Use XML::HTMLParser.string instead")
90
+ @context = XML::HTMLParser::Context.string(value)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,60 @@
1
+ module LibXML
2
+ module XML
3
+ class Namespace
4
+ include Comparable
5
+ include Enumerable
6
+
7
+ # call-seq:
8
+ # namespace1 <=> namespace2
9
+ #
10
+ # Compares two namespace objects. Namespace objects are
11
+ # considered equal if their prefixes and hrefs are the same.
12
+ def <=>(other)
13
+ if self.prefix.nil? and other.prefix.nil?
14
+ self.href <=> other.href
15
+ elsif self.prefix.nil?
16
+ -1
17
+ elsif other.prefix.nil?
18
+ 1
19
+ else
20
+ self.prefix <=> other.prefix
21
+ end
22
+ end
23
+
24
+ # call-seq:
25
+ # namespace.each {|ns| .. }
26
+ #
27
+ # libxml stores namespaces in memory as a linked list.
28
+ # Use the each method to iterate over the list. Note
29
+ # the first namespace in the loop is the current namespace.
30
+ #
31
+ # Usage:
32
+ # namespace.each do |ns|
33
+ # ..
34
+ # end
35
+ def each
36
+ ns = self
37
+
38
+ while ns
39
+ yield ns
40
+ ns = ns.next
41
+ end
42
+ end
43
+
44
+ # call-seq:
45
+ # namespace.to_s -> "string"
46
+ #
47
+ # Returns the string represenation of a namespace.
48
+ #
49
+ # Usage:
50
+ # namespace.to_s
51
+ def to_s
52
+ if self.prefix
53
+ "#{self.prefix}:#{self.href}"
54
+ else
55
+ self.href
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,36 @@
1
+ module LibXML
2
+ module XML
3
+ class Namespaces
4
+ # call-seq:
5
+ # namespace.default -> XML::Namespace
6
+ #
7
+ # Returns the default namespace for this node or nil.
8
+ #
9
+ # Usage:
10
+ # doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
11
+ # ns = doc.root.namespaces.default_namespace
12
+ # assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
13
+ def default
14
+ find_by_prefix(nil)
15
+ end
16
+
17
+ # call-seq:
18
+ # namespace.default_prefix = "string"
19
+ #
20
+ # Assigns a name (prefix) to the default namespace.
21
+ # This makes it much easier to perform XML::XPath
22
+ # searches.
23
+ #
24
+ # Usage:
25
+ # doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
26
+ # doc.root.namespaces.default_prefix = 'soap'
27
+ # node = doc.root.find_first('soap:Envelope')
28
+ def default_prefix=(prefix)
29
+ # Find default prefix
30
+ ns = find_by_prefix(nil)
31
+ raise(ArgumentError, "No default namespace was found") unless ns
32
+ Namespace.new(self.node, prefix, ns.href)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,385 @@
1
+ require 'stringio'
2
+
3
+ module LibXML
4
+ module XML
5
+ class Node
6
+ # Determines whether this node has attributes
7
+ def attributes?
8
+ attributes.length > 0
9
+ end
10
+
11
+ # Create a shallow copy of the node. To create
12
+ # a deep copy call Node#copy(true)
13
+ def clone
14
+ copy(false)
15
+ end
16
+
17
+ # call-seq:
18
+ # node.inner_xml -> "string"
19
+ # node.inner_xml(:indent => true, :encoding => 'UTF-8', :level => 0) -> "string"
20
+ #
21
+ # Converts a node's children, to a string representation. To include
22
+ # the node, use XML::Node#to_s. For more information about
23
+ # the supported options, see XML::Node#to_s.
24
+ def inner_xml(options = Hash.new)
25
+ io = StringIO.new
26
+
27
+ self.each do |node|
28
+ io << node.to_s(options)
29
+ end
30
+
31
+ io.string
32
+ end
33
+
34
+ # :call-seq:
35
+ # node.dup -> XML::Node
36
+ #
37
+ # Create a shallow copy of the node. To create
38
+ # a deep copy call Node#copy(true)
39
+ def dup
40
+ copy(false)
41
+ end
42
+
43
+ # call-seq:
44
+ # node.context(namespaces=nil) -> XPath::Context
45
+ #
46
+ # Returns a new XML::XPathContext for the current node.
47
+ #
48
+ # Namespaces is an optional array of XML::NS objects
49
+ def context(nslist = nil)
50
+ if not self.doc
51
+ raise(TypeError, "A node must belong to a document before a xpath context can be created")
52
+ end
53
+
54
+ context = XPath::Context.new(self)
55
+ context.node = self
56
+ context.register_namespaces_from_node(self)
57
+ context.register_namespaces_from_node(self.doc.root)
58
+ context.register_namespaces(nslist) if nslist
59
+ context
60
+ end
61
+
62
+ # call-seq:
63
+ # node.find(namespaces=nil) -> XPath::XPathObject
64
+ #
65
+ # Return nodes matching the specified xpath expression.
66
+ # For more information, please refer to the documentation
67
+ # for XML::Document#find.
68
+ #
69
+ # Namespaces is an optional array of XML::NS objects
70
+ def find(xpath, nslist = nil)
71
+ self.context(nslist).find(xpath)
72
+ end
73
+
74
+ # call-seq:
75
+ # node.find_first(namespaces=nil) -> XML::Node
76
+ #
77
+ # Return the first node matching the specified xpath expression.
78
+ # For more information, please refer to the documentation
79
+ # for the #find method.
80
+ def find_first(xpath, nslist = nil)
81
+ find(xpath, nslist).first
82
+ end
83
+
84
+ # call-seq:
85
+ # node.namespacess -> XML::Namespaces
86
+ #
87
+ # Returns this node's XML::Namespaces object,
88
+ # which is used to access the namespaces
89
+ # associated with this node.
90
+ def namespaces
91
+ @namespaces ||= XML::Namespaces.new(self)
92
+ end
93
+
94
+ # ------- Traversal ----------------
95
+ # Iterates over this node's attributes.
96
+ #
97
+ # doc = XML::Document.new('model/books.xml')
98
+ # doc.root.each_attr {|attr| puts attr}
99
+ def each_attr
100
+ attributes.each do |attr|
101
+ yield(attr)
102
+ end
103
+ end
104
+
105
+ # Iterates over this node's child elements (nodes
106
+ # that have a node_type == ELEMENT_NODE).
107
+ #
108
+ # doc = XML::Document.new('model/books.xml')
109
+ # doc.root.each_element {|element| puts element}
110
+ def each_element
111
+ each do |node|
112
+ yield(node) if node.node_type == ELEMENT_NODE
113
+ end
114
+ end
115
+
116
+ # Determines whether this node has a parent node
117
+ def parent?
118
+ not parent.nil?
119
+ end
120
+
121
+ # Determines whether this node has a first node
122
+ def first?
123
+ not first.nil?
124
+ end
125
+
126
+ # Returns this node's children as an array.
127
+ def children
128
+ entries
129
+ end
130
+
131
+ # Determines whether this node has a next node
132
+ def next?
133
+ not self.next.nil?
134
+ end
135
+
136
+ # Determines whether this node has a previous node
137
+ def prev?
138
+ not prev.nil?
139
+ end
140
+
141
+ # Determines whether this node has a last node
142
+ def last?
143
+ not last.nil?
144
+ end
145
+
146
+
147
+ # ------- Node Types ----------------
148
+
149
+ # Returns this node's type name
150
+ def node_type_name
151
+ case node_type
152
+ # Most common choices first
153
+ when ATTRIBUTE_NODE
154
+ 'attribute'
155
+ when DOCUMENT_NODE
156
+ 'document_xml'
157
+ when ELEMENT_NODE
158
+ 'element'
159
+ when TEXT_NODE
160
+ 'text'
161
+
162
+ # Now the rest
163
+ when ATTRIBUTE_DECL
164
+ 'attribute_decl'
165
+ when CDATA_SECTION_NODE
166
+ 'cdata'
167
+ when COMMENT_NODE
168
+ 'comment'
169
+ when DOCB_DOCUMENT_NODE
170
+ 'document_docbook'
171
+ when DOCUMENT_FRAG_NODE
172
+ 'fragment'
173
+ when DOCUMENT_TYPE_NODE
174
+ 'doctype'
175
+ when DTD_NODE
176
+ 'dtd'
177
+ when ELEMENT_DECL
178
+ 'elem_decl'
179
+ when ENTITY_DECL
180
+ 'entity_decl'
181
+ when ENTITY_NODE
182
+ 'entity'
183
+ when ENTITY_REF_NODE
184
+ 'entity_ref'
185
+ when HTML_DOCUMENT_NODE
186
+ 'document_html'
187
+ when NAMESPACE_DECL
188
+ 'namespace'
189
+ when NOTATION_NODE
190
+ 'notation'
191
+ when PI_NODE
192
+ 'pi'
193
+ when XINCLUDE_START
194
+ 'xinclude_start'
195
+ when XINCLUDE_END
196
+ 'xinclude_end'
197
+ else
198
+ raise(UnknownType, "Unknown node type: %n", node.node_type);
199
+ end
200
+ end
201
+
202
+ # Specifies if this is an attribute node
203
+ def attribute?
204
+ node_type == ATTRIBUTE_NODE
205
+ end
206
+
207
+ # Specifies if this is an attribute declaration node
208
+ def attribute_decl?
209
+ node_type == ATTRIBUTE_DECL
210
+ end
211
+
212
+ # Specifies if this is an CDATA node
213
+ def cdata?
214
+ node_type == CDATA_SECTION_NODE
215
+ end
216
+
217
+ # Specifies if this is an comment node
218
+ def comment?
219
+ node_type == COMMENT_NODE
220
+ end
221
+
222
+ # Specifies if this is an docbook node
223
+ def docbook_doc?
224
+ node_type == DOCB_DOCUMENT_NODE
225
+ end
226
+
227
+ # Specifies if this is an docbook node
228
+ def doctype?
229
+ node_type == DOCUMENT_TYPE_NODE
230
+ end
231
+
232
+ # Specifies if this is an DOCTYPE node
233
+ def document?
234
+ node_type == DOCUMENT_NODE
235
+ end
236
+
237
+ # Specifies if this is an DTD node
238
+ def dtd?
239
+ node_type == DTD_NODE
240
+ end
241
+
242
+ # Specifies if this is an element node
243
+ def element?
244
+ node_type == ELEMENT_NODE
245
+ end
246
+
247
+ # Specifies if this is an entity node
248
+ def entity?
249
+ node_type == ENTITY_NODE
250
+ end
251
+
252
+ # Specifies if this is an element declaration node
253
+ def element_decl?
254
+ node_type == ELEMENT_DECL
255
+ end
256
+
257
+ # Specifies if this is an entity reference node
258
+ def entity_ref?
259
+ node_type == ENTITY_REF_NODE
260
+ end
261
+
262
+ # Specifies if this is a fragment node
263
+ def fragment?
264
+ node_type == DOCUMENT_FRAG_NODE
265
+ end
266
+
267
+ # Specifies if this is a html document node
268
+ def html_doc?
269
+ node_type == HTML_DOCUMENT_NODE
270
+ end
271
+
272
+ # Specifies if this is a namespace node (not if it
273
+ # has a namepsace)
274
+ def namespace?
275
+ node_type == NAMESPACE_DECL
276
+ end
277
+
278
+ # Specifies if this is a notation node
279
+ def notation?
280
+ node_type == NOTATION_NODE
281
+ end
282
+
283
+ # Specifies if this is a processiong instruction node
284
+ def pi?
285
+ node_type == PI_NODE
286
+ end
287
+
288
+ # Specifies if this is a text node
289
+ def text?
290
+ node_type == TEXT_NODE
291
+ end
292
+
293
+ # Specifies if this is an xinclude end node
294
+ def xinclude_end?
295
+ node_type == XINCLUDE_END
296
+ end
297
+
298
+ # Specifies if this is an xinclude start node
299
+ def xinclude_start?
300
+ node_type == XINCLUDE_START
301
+ end
302
+
303
+ alias :child? :first?
304
+ alias :children? :first?
305
+ alias :child :first
306
+ alias :each_child :each
307
+
308
+ # --- Deprecated Output ---
309
+ # :stopdoc:
310
+ def dump
311
+ warn('Node#dump is deprecated. Use Node#to_s instead.')
312
+ self.to_s
313
+ end
314
+
315
+ # --- Deprecated DOM Manipulation ---
316
+ def child_add(node)
317
+ warn('Node#child_add is deprecated. Use Node#<< instead.')
318
+ self << node
319
+ end
320
+
321
+ def child=(node)
322
+ warn('Node#child= is deprecated. Use Node#<< instead.')
323
+ self << node
324
+ end
325
+
326
+ # --- Deprecated Namespaces ---
327
+ def namespace
328
+ warn('Node#namespace is deprecated. Use Node#namespaces instead.')
329
+ self.namespaces.entries
330
+ end
331
+
332
+ def namespace=(value)
333
+ warn('Node#namespace= is deprecated. Use Node#namespaces.namespace= instead.')
334
+ self.namespaces.namespace = value
335
+ end
336
+
337
+ def namespace_node
338
+ warn('Node#namespace_node is deprecated. Use Node#namespaces.namespace instead.')
339
+ self.namespaces.namespace
340
+ end
341
+
342
+ def ns
343
+ warn('Node#ns is deprecated. Use Node#namespaces.namespace instead.')
344
+ self.namespaces.namespace
345
+ end
346
+
347
+ def ns?
348
+ warn('Node#ns? is deprecated. Use !Node#namespaces.namespace.nil? instead.')
349
+ !self.namespaces.namespace.nil?
350
+ end
351
+
352
+ def ns_def
353
+ warn('Node#ns_def is deprecated. Use Node#namespaces.definitions instead.')
354
+ self.namespaces.definitions
355
+ end
356
+
357
+ def ns_def?
358
+ warn('Node#ns_def? is deprecated. Use !Node#namespaces.definitions.nil? instead.')
359
+ !self.namespaces.definitions.nil?
360
+ end
361
+
362
+ def base
363
+ warn('Node#base is deprecated. Use Node#base_uri.')
364
+ self.base_uri
365
+ end
366
+
367
+ def base=(value)
368
+ warn('Node#base= is deprecated. Use Node#base_uri=.')
369
+ self.base_uri = value
370
+ end
371
+
372
+ def search_ns(prefix)
373
+ warn('Node#search_ns is deprecated. Use Node#namespaces.find_by_prefix instead.')
374
+ self.namespaces.find_by_prefix(prefix)
375
+ end
376
+
377
+ def search_href(href)
378
+ warn('Node#search_href is deprecated. Use Node#namespaces.find_by_href instead.')
379
+ self.namespaces.find_by_href(href)
380
+ end
381
+
382
+ # :startdoc:
383
+ end
384
+ end
385
+ end