libxml-ruby 2.0.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/HISTORY +516 -0
  2. data/LICENSE +23 -0
  3. data/MANIFEST +165 -0
  4. data/README.rdoc +161 -0
  5. data/Rakefile +82 -0
  6. data/ext/libxml/extconf.rb +122 -0
  7. data/ext/libxml/libxml.c +93 -0
  8. data/ext/libxml/ruby_libxml.h +101 -0
  9. data/ext/libxml/ruby_xml.c +893 -0
  10. data/ext/libxml/ruby_xml.h +10 -0
  11. data/ext/libxml/ruby_xml_attr.c +352 -0
  12. data/ext/libxml/ruby_xml_attr.h +14 -0
  13. data/ext/libxml/ruby_xml_attr_decl.c +171 -0
  14. data/ext/libxml/ruby_xml_attr_decl.h +13 -0
  15. data/ext/libxml/ruby_xml_attributes.c +277 -0
  16. data/ext/libxml/ruby_xml_attributes.h +17 -0
  17. data/ext/libxml/ruby_xml_cbg.c +85 -0
  18. data/ext/libxml/ruby_xml_document.c +958 -0
  19. data/ext/libxml/ruby_xml_document.h +17 -0
  20. data/ext/libxml/ruby_xml_dtd.c +257 -0
  21. data/ext/libxml/ruby_xml_dtd.h +9 -0
  22. data/ext/libxml/ruby_xml_encoding.c +221 -0
  23. data/ext/libxml/ruby_xml_encoding.h +16 -0
  24. data/ext/libxml/ruby_xml_error.c +1004 -0
  25. data/ext/libxml/ruby_xml_error.h +14 -0
  26. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  27. data/ext/libxml/ruby_xml_html_parser.h +12 -0
  28. data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
  29. data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
  30. data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
  31. data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
  32. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  33. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  34. data/ext/libxml/ruby_xml_io.c +30 -0
  35. data/ext/libxml/ruby_xml_io.h +9 -0
  36. data/ext/libxml/ruby_xml_namespace.c +170 -0
  37. data/ext/libxml/ruby_xml_namespace.h +12 -0
  38. data/ext/libxml/ruby_xml_namespaces.c +295 -0
  39. data/ext/libxml/ruby_xml_namespaces.h +11 -0
  40. data/ext/libxml/ruby_xml_node.c +1386 -0
  41. data/ext/libxml/ruby_xml_node.h +13 -0
  42. data/ext/libxml/ruby_xml_parser.c +94 -0
  43. data/ext/libxml/ruby_xml_parser.h +14 -0
  44. data/ext/libxml/ruby_xml_parser_context.c +982 -0
  45. data/ext/libxml/ruby_xml_parser_context.h +12 -0
  46. data/ext/libxml/ruby_xml_parser_options.c +68 -0
  47. data/ext/libxml/ruby_xml_parser_options.h +14 -0
  48. data/ext/libxml/ruby_xml_reader.c +1057 -0
  49. data/ext/libxml/ruby_xml_reader.h +14 -0
  50. data/ext/libxml/ruby_xml_relaxng.c +111 -0
  51. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  52. data/ext/libxml/ruby_xml_sax2_handler.c +334 -0
  53. data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
  54. data/ext/libxml/ruby_xml_sax_parser.c +136 -0
  55. data/ext/libxml/ruby_xml_sax_parser.h +12 -0
  56. data/ext/libxml/ruby_xml_schema.c +159 -0
  57. data/ext/libxml/ruby_xml_schema.h +11 -0
  58. data/ext/libxml/ruby_xml_version.h +9 -0
  59. data/ext/libxml/ruby_xml_xinclude.c +18 -0
  60. data/ext/libxml/ruby_xml_xinclude.h +13 -0
  61. data/ext/libxml/ruby_xml_xpath.c +107 -0
  62. data/ext/libxml/ruby_xml_xpath.h +12 -0
  63. data/ext/libxml/ruby_xml_xpath_context.c +390 -0
  64. data/ext/libxml/ruby_xml_xpath_context.h +11 -0
  65. data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
  66. data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
  67. data/ext/libxml/ruby_xml_xpath_object.c +336 -0
  68. data/ext/libxml/ruby_xml_xpath_object.h +19 -0
  69. data/ext/libxml/ruby_xml_xpointer.c +101 -0
  70. data/ext/libxml/ruby_xml_xpointer.h +13 -0
  71. data/ext/mingw/Rakefile +34 -0
  72. data/ext/mingw/build.rake +41 -0
  73. data/ext/vc/libxml_ruby.sln +26 -0
  74. data/lib/1.8/libxml_ruby.so +0 -0
  75. data/lib/1.9/libxml_ruby.so +0 -0
  76. data/lib/libxml.rb +30 -0
  77. data/lib/libxml/attr.rb +113 -0
  78. data/lib/libxml/attr_decl.rb +80 -0
  79. data/lib/libxml/attributes.rb +14 -0
  80. data/lib/libxml/document.rb +192 -0
  81. data/lib/libxml/error.rb +90 -0
  82. data/lib/libxml/hpricot.rb +78 -0
  83. data/lib/libxml/html_parser.rb +96 -0
  84. data/lib/libxml/namespace.rb +62 -0
  85. data/lib/libxml/namespaces.rb +38 -0
  86. data/lib/libxml/node.rb +399 -0
  87. data/lib/libxml/ns.rb +22 -0
  88. data/lib/libxml/parser.rb +367 -0
  89. data/lib/libxml/properties.rb +23 -0
  90. data/lib/libxml/reader.rb +29 -0
  91. data/lib/libxml/sax_callbacks.rb +180 -0
  92. data/lib/libxml/sax_parser.rb +58 -0
  93. data/lib/libxml/tree.rb +29 -0
  94. data/lib/libxml/xpath_object.rb +16 -0
  95. data/lib/xml.rb +16 -0
  96. data/lib/xml/libxml.rb +10 -0
  97. data/libxml-ruby.gemspec +50 -0
  98. data/script/benchmark/depixelate +634 -0
  99. data/script/benchmark/hamlet.xml +9055 -0
  100. data/script/benchmark/parsecount +170 -0
  101. data/script/benchmark/sock_entries.xml +507 -0
  102. data/script/benchmark/throughput +41 -0
  103. data/script/test +6 -0
  104. data/setup.rb +1585 -0
  105. data/test/etc_doc_to_s.rb +21 -0
  106. data/test/ets_doc_file.rb +17 -0
  107. data/test/ets_doc_to_s.rb +23 -0
  108. data/test/ets_gpx.rb +28 -0
  109. data/test/ets_node_gc.rb +23 -0
  110. data/test/ets_test.xml +2 -0
  111. data/test/ets_tsr.rb +11 -0
  112. data/test/model/atom.xml +13 -0
  113. data/test/model/bands.iso-8859-1.xml +5 -0
  114. data/test/model/bands.utf-8.xml +5 -0
  115. data/test/model/bands.xml +5 -0
  116. data/test/model/books.xml +146 -0
  117. data/test/model/merge_bug_data.xml +58 -0
  118. data/test/model/ruby-lang.html +238 -0
  119. data/test/model/rubynet.xml +79 -0
  120. data/test/model/rubynet_project +1 -0
  121. data/test/model/shiporder.rnc +28 -0
  122. data/test/model/shiporder.rng +86 -0
  123. data/test/model/shiporder.xml +23 -0
  124. data/test/model/shiporder.xsd +31 -0
  125. data/test/model/soap.xml +27 -0
  126. data/test/model/xinclude.xml +5 -0
  127. data/test/rb-magic-comment.rb +33 -0
  128. data/test/tc_attr.rb +181 -0
  129. data/test/tc_attr_decl.rb +133 -0
  130. data/test/tc_attributes.rb +135 -0
  131. data/test/tc_deprecated_require.rb +13 -0
  132. data/test/tc_document.rb +119 -0
  133. data/test/tc_document_write.rb +187 -0
  134. data/test/tc_dtd.rb +125 -0
  135. data/test/tc_error.rb +138 -0
  136. data/test/tc_html_parser.rb +140 -0
  137. data/test/tc_namespace.rb +62 -0
  138. data/test/tc_namespaces.rb +177 -0
  139. data/test/tc_node.rb +258 -0
  140. data/test/tc_node_cdata.rb +51 -0
  141. data/test/tc_node_comment.rb +33 -0
  142. data/test/tc_node_copy.rb +42 -0
  143. data/test/tc_node_edit.rb +160 -0
  144. data/test/tc_node_text.rb +71 -0
  145. data/test/tc_node_write.rb +108 -0
  146. data/test/tc_node_xlink.rb +29 -0
  147. data/test/tc_parser.rb +336 -0
  148. data/test/tc_parser_context.rb +189 -0
  149. data/test/tc_properties.rb +39 -0
  150. data/test/tc_reader.rb +298 -0
  151. data/test/tc_relaxng.rb +54 -0
  152. data/test/tc_sax_parser.rb +276 -0
  153. data/test/tc_schema.rb +53 -0
  154. data/test/tc_traversal.rb +222 -0
  155. data/test/tc_xinclude.rb +21 -0
  156. data/test/tc_xml.rb +226 -0
  157. data/test/tc_xpath.rb +195 -0
  158. data/test/tc_xpath_context.rb +80 -0
  159. data/test/tc_xpath_expression.rb +38 -0
  160. data/test/tc_xpointer.rb +74 -0
  161. data/test/test_helper.rb +14 -0
  162. data/test/test_suite.rb +39 -0
  163. metadata +254 -0
@@ -0,0 +1,13 @@
1
+ /* $Id$ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RXML_XPOINTER__
6
+ #define __RXML_XPOINTER__
7
+
8
+ extern VALUE cXMLXPointer;
9
+
10
+ void rxml_init_xpointer(void);
11
+ VALUE rxml_xpointer_point2(VALUE node, VALUE xptr_str);
12
+
13
+ #endif
@@ -0,0 +1,34 @@
1
+ # We can't use Ruby's standard build procedures
2
+ # on Windows because the Ruby executable is
3
+ # built with VC++ while here we want to build
4
+ # with MingW. So just roll our own...
5
+
6
+ require 'fileutils'
7
+ require 'rbconfig'
8
+
9
+ EXTENSION_NAME = "libxml_ruby.#{Config::CONFIG["DLEXT"]}"
10
+
11
+ # MingW insists the import library is .dll.a
12
+ EXTENSION_LIB_NAME = "libxml_ruby.dll.a"
13
+
14
+ # This is called when the Windows GEM is installed!
15
+ task :install do
16
+ # Gems will pass these two environment variables:
17
+ # RUBYARCHDIR=#{dest_path}
18
+ # RUBYLIBDIR=#{dest_path}
19
+
20
+ dest_path = ENV['RUBYLIBDIR']
21
+
22
+ # Copy the extension
23
+ cp(EXTENSION_NAME, dest_path)
24
+
25
+ # Copy the import library (used by libxslt)
26
+ cp(EXTENSION_LIB_NAME, dest_path)
27
+
28
+ # Copy dlls
29
+ Dir.glob('*.dll').each do |dll|
30
+ cp(dll, dest_path)
31
+ end
32
+ end
33
+
34
+ task :default => :install
@@ -0,0 +1,41 @@
1
+ # We can't use Ruby's standard build procedures
2
+ # on Windows because the Ruby executable is
3
+ # built with VC++ while here we want to build
4
+ # with MingW. So just roll our own...
5
+
6
+ require 'rake/clean'
7
+ require 'rbconfig'
8
+
9
+ RUBY_INCLUDE_DIR = Config::CONFIG["archdir"]
10
+ RUBY_BIN_DIR = Config::CONFIG["bindir"]
11
+ RUBY_LIB_DIR = Config::CONFIG["libdir"]
12
+ RUBY_SHARED_LIB = Config::CONFIG["LIBRUBY"]
13
+ RUBY_SHARED_DLL = RUBY_SHARED_LIB.gsub(/^lib/, '').gsub(/lib$/, 'dll').gsub(/\.a$/, '')
14
+
15
+ EXTENSION_NAME = "libxml_ruby.#{Config::CONFIG["DLEXT"]}"
16
+ # MingW insists the import library is .dll.a
17
+ EXTENSION_LIB_NAME = "libxml_ruby.dll.a"
18
+
19
+ CLEAN.include('*.o')
20
+ CLOBBER.include(EXTENSION_NAME)
21
+ CLOBBER.include(EXTENSION_LIB_NAME)
22
+
23
+ task :default => "libxml"
24
+
25
+ SRC = FileList['../libxml/*.c']
26
+ OBJ = SRC.collect do |file_name|
27
+ File.basename(file_name).ext('o')
28
+ end
29
+
30
+ SRC.each do |srcfile|
31
+ objfile = File.basename(srcfile).ext('o')
32
+ file objfile => srcfile do
33
+ command = "gcc -c -O2 -Wall -o #{objfile} -I/usr/local/include/libxml2 #{srcfile} -I#{RUBY_INCLUDE_DIR}"
34
+ sh "sh -c '#{command}'"
35
+ end
36
+ end
37
+
38
+ file "libxml" => OBJ do
39
+ command = "gcc -shared -Wl,--enable-auto-import -o #{EXTENSION_NAME} -Wl,--out-implib,#{EXTENSION_LIB_NAME} -L/usr/local/lib #{OBJ} -lxml2 #{RUBY_BIN_DIR}/#{RUBY_SHARED_DLL}"
40
+ sh "sh -c '#{command}'"
41
+ end
@@ -0,0 +1,26 @@
1
+ 
2
+ Microsoft Visual Studio Solution File, Format Version 11.00
3
+ # Visual Studio 2010
4
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libxml_ruby", "libxml_ruby_18\libxml_ruby.vcxproj", "{0B65CD1D-EEB9-41AE-93BB-75496E504152}"
5
+ EndProject
6
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libxml_ruby_19", "libxml_ruby_19\libxml_ruby_19.vcxproj", "{0E73156F-E619-4FD9-8327-113FE3CC942E}"
7
+ EndProject
8
+ Global
9
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
10
+ Debug|Win32 = Debug|Win32
11
+ Release|Win32 = Release|Win32
12
+ EndGlobalSection
13
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
14
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Debug|Win32.ActiveCfg = Debug|Win32
15
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Debug|Win32.Build.0 = Debug|Win32
16
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Release|Win32.ActiveCfg = Release|Win32
17
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Release|Win32.Build.0 = Release|Win32
18
+ {0E73156F-E619-4FD9-8327-113FE3CC942E}.Debug|Win32.ActiveCfg = Debug|Win32
19
+ {0E73156F-E619-4FD9-8327-113FE3CC942E}.Debug|Win32.Build.0 = Debug|Win32
20
+ {0E73156F-E619-4FD9-8327-113FE3CC942E}.Release|Win32.ActiveCfg = Release|Win32
21
+ {0E73156F-E619-4FD9-8327-113FE3CC942E}.Release|Win32.Build.0 = Release|Win32
22
+ EndGlobalSection
23
+ GlobalSection(SolutionProperties) = preSolution
24
+ HideSolutionNode = FALSE
25
+ EndGlobalSection
26
+ EndGlobal
Binary file
Binary file
@@ -0,0 +1,30 @@
1
+ # encoding: UTF-8
2
+
3
+ # Load the C-based binding.
4
+ begin
5
+ RUBY_VERSION =~ /(\d+.\d+)/
6
+ require "#{$1}/libxml_ruby"
7
+ rescue LoadError
8
+ require "libxml_ruby"
9
+ end
10
+
11
+ # Load Ruby supporting code.
12
+ require 'libxml/error'
13
+ require 'libxml/parser'
14
+ require 'libxml/document'
15
+ require 'libxml/namespaces'
16
+ require 'libxml/namespace'
17
+ require 'libxml/node'
18
+ require 'libxml/ns'
19
+ require 'libxml/attributes'
20
+ require 'libxml/attr'
21
+ require 'libxml/attr_decl'
22
+ require 'libxml/tree'
23
+ require 'libxml/reader'
24
+ require 'libxml/html_parser'
25
+ require 'libxml/sax_parser'
26
+ require 'libxml/sax_callbacks'
27
+ require 'libxml/xpath_object'
28
+
29
+ # Deprecated
30
+ require 'libxml/properties'
@@ -0,0 +1,113 @@
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
+ #
52
+ # call-seq:
53
+ # attr.parent? -> (true|false)
54
+ #
55
+ # Determine whether this attribute has a parent.
56
+ def parent?
57
+ not self.parent.nil?
58
+ end
59
+
60
+ # call-seq:
61
+ # attr.prev? -> (true|false)
62
+ #
63
+ # Determine whether there is a previous attribute.
64
+ def prev?
65
+ not self.prev.nil?
66
+ end
67
+
68
+ # Returns this node's type name
69
+ def node_type_name
70
+ if node_type == Node::ATTRIBUTE_NODE
71
+ 'attribute'
72
+ else
73
+ raise(UnknownType, "Unknown node type: %n", node.node_type);
74
+ end
75
+ end
76
+
77
+ # Iterates nodes and attributes
78
+ def siblings(node, &blk)
79
+ if n = node
80
+ loop do
81
+ blk.call(n)
82
+ break unless n = n.next
83
+ end
84
+ end
85
+ end
86
+
87
+ def each_sibling(&blk)
88
+ siblings(self,&blk)
89
+ end
90
+
91
+ alias :each_attr :each_sibling
92
+ alias :each :each_sibling
93
+
94
+ def to_h
95
+ inject({}) do |h,a|
96
+ h[a.name] = a.value
97
+ h
98
+ end
99
+ end
100
+
101
+ def to_a
102
+ inject([]) do |ary,a|
103
+ ary << [a.name, a.value]
104
+ ary
105
+ end
106
+ end
107
+
108
+ def to_s
109
+ "#{name} = #{value}"
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +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
@@ -0,0 +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
14
+ end
@@ -0,0 +1,192 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Document
6
+ # call-seq:
7
+ # XML::Document.document(document) -> XML::Document
8
+ #
9
+ # Creates a new document based on the specified document.
10
+ #
11
+ # Parameters:
12
+ #
13
+ # document - A preparsed document.
14
+ def self.document(value)
15
+ Parser.document(value).parse
16
+ end
17
+
18
+ # call-seq:
19
+ # XML::Document.file(path) -> XML::Document
20
+ # XML::Document.file(path, :encoding => XML::Encoding::UTF_8,
21
+ # :options => XML::Parser::Options::NOENT) -> XML::Document
22
+ #
23
+ # Creates a new document from the specified file or uri.
24
+ #
25
+ # You may provide an optional hash table to control how the
26
+ # parsing is performed. Valid options are:
27
+ #
28
+ # encoding - The document encoding, defaults to nil. Valid values
29
+ # are the encoding constants defined on XML::Encoding.
30
+ # options - Parser options. Valid values are the constants defined on
31
+ # XML::Parser::Options. Mutliple options can be combined
32
+ # by using Bitwise OR (|).
33
+ def self.file(value, options = {})
34
+ Parser.file(value, options).parse
35
+ end
36
+
37
+ # call-seq:
38
+ # XML::Document.io(io) -> XML::Document
39
+ # XML::Document.io(io, :encoding => XML::Encoding::UTF_8,
40
+ # :options => XML::Parser::Options::NOENT
41
+ # :base_uri="http://libxml.org") -> XML::Document
42
+ #
43
+ # Creates a new document from the specified io object.
44
+ #
45
+ # Parameters:
46
+ #
47
+ # io - io object that contains the xml to parser
48
+ # base_uri - The base url for the parsed document.
49
+ # encoding - The document encoding, defaults to nil. Valid values
50
+ # are the encoding constants defined on XML::Encoding.
51
+ # options - Parser options. Valid values are the constants defined on
52
+ # XML::Parser::Options. Mutliple options can be combined
53
+ # by using Bitwise OR (|).
54
+ def self.io(value, options = {})
55
+ Parser.io(value, options).parse
56
+ end
57
+
58
+ # call-seq:
59
+ # XML::Document.string(string)
60
+ # XML::Document.string(string, :encoding => XML::Encoding::UTF_8,
61
+ # :options => XML::Parser::Options::NOENT
62
+ # :base_uri="http://libxml.org") -> XML::Document
63
+ #
64
+ # Creates a new document from the specified string.
65
+ #
66
+ # You may provide an optional hash table to control how the
67
+ # parsing is performed. Valid options are:
68
+ #
69
+ # base_uri - The base url for the parsed document.
70
+ # encoding - The document encoding, defaults to nil. Valid values
71
+ # are the encoding constants defined on XML::Encoding.
72
+ # options - Parser options. Valid values are the constants defined on
73
+ # XML::Parser::Options. Mutliple options can be combined
74
+ # by using Bitwise OR (|).
75
+ def self.string(value, options = {})
76
+ Parser.string(value, options).parse
77
+ end
78
+
79
+ # Returns a new XML::XPathContext for the document.
80
+ #
81
+ # call-seq:
82
+ # document.context(namespaces=nil) -> XPath::Context
83
+ #
84
+ # Namespaces is an optional array of XML::NS objects
85
+ def context(nslist = nil)
86
+ context = XPath::Context.new(self)
87
+ context.node = self.root
88
+ context.register_namespaces_from_node(self.root)
89
+ context.register_namespaces(nslist) if nslist
90
+ context
91
+ end
92
+
93
+ # Return the nodes matching the specified xpath expression,
94
+ # optionally using the specified namespace. For more
95
+ # information about working with namespaces, please refer
96
+ # to the XML::XPath documentation.
97
+ #
98
+ # Parameters:
99
+ # * xpath - The xpath expression as a string
100
+ # * namespaces - An optional list of namespaces (see XML::XPath for information).
101
+ # * Returns - XML::XPath::Object
102
+ #
103
+ # document.find('/foo', 'xlink:http://www.w3.org/1999/xlink')
104
+ #
105
+ # IMPORTANT - The returned XML::Node::Set must be freed before
106
+ # its associated document. In a running Ruby program this will
107
+ # happen automatically via Ruby's mark and sweep garbage collector.
108
+ # However, if the program exits, Ruby does not guarantee the order
109
+ # in which objects are freed
110
+ # (see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/17700).
111
+ # As a result, the associated document may be freed before the node
112
+ # list, which will cause a segmentation fault.
113
+ # To avoid this, use the following (non-ruby like) coding style:
114
+ #
115
+ # nodes = doc.find('/header')
116
+ # nodes.each do |node|
117
+ # ... do stuff ...
118
+ # end
119
+ # # nodes = nil # GC.start
120
+ def find(xpath, nslist = nil)
121
+ self.context(nslist).find(xpath)
122
+ end
123
+
124
+ # Return the first node matching the specified xpath expression.
125
+ # For more information, please refer to the documentation
126
+ # for XML::Document#find.
127
+ def find_first(xpath, nslist = nil)
128
+ find(xpath, nslist).first
129
+ end
130
+
131
+ # Returns this node's type name
132
+ def node_type_name
133
+ case node_type
134
+ when XML::Node::DOCUMENT_NODE
135
+ 'document_xml'
136
+ when XML::Node::DOCB_DOCUMENT_NODE
137
+ 'document_docbook'
138
+ when XML::Node::HTML_DOCUMENT_NODE
139
+ 'document_html'
140
+ else
141
+ raise(UnknownType, "Unknown node type: %n", node.node_type);
142
+ end
143
+ end
144
+ # :enddoc:
145
+
146
+ # Specifies if this is an DOCTYPE node
147
+ def document?
148
+ node_type == XML::Node::DOCUMENT_NODE
149
+ end
150
+
151
+ # Specifies if this is an docbook node
152
+ def docbook_doc?
153
+ node_type == XML::Node::DOCB_DOCUMENT_NODE
154
+ end
155
+
156
+ # Specifies if this is an html node
157
+ def html_doc?
158
+ node_type == XML::Node::HTML_DOCUMENT_NODE
159
+ end
160
+
161
+ def dump
162
+ warn('Document#dump is deprecated. Use Document#to_s instead.')
163
+ self.to_s
164
+ end
165
+
166
+ def format_dump
167
+ warn('Document#format_dump is deprecated. Use Document#to_s instead.')
168
+ self.to_s
169
+ end
170
+
171
+ def debug_dump
172
+ warn('Document#debug_dump is deprecated. Use Document#debug instead.')
173
+ self.debug
174
+ end
175
+
176
+ def debug_dump_head
177
+ warn('Document#debug_dump_head is deprecated. Use Document#debug instead.')
178
+ self.debug
179
+ end
180
+
181
+ def debug_format_dump
182
+ warn('Document#debug_format_dump is deprecated. Use Document#to_s instead.')
183
+ self.to_s
184
+ end
185
+
186
+ def reader
187
+ warn('Document#reader is deprecated. Use XML::Reader.document(self) instead.')
188
+ XML::Reader.document(self)
189
+ end
190
+ end
191
+ end
192
+ end