libxml-ruby 2.9.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/HISTORY +790 -0
- data/LICENSE +21 -0
- data/MANIFEST +166 -0
- data/README.rdoc +184 -0
- data/Rakefile +81 -0
- data/ext/libxml/extconf.h +4 -0
- data/ext/libxml/extconf.rb +57 -0
- data/ext/libxml/libxml.c +80 -0
- data/ext/libxml/libxml_ruby.def +35 -0
- data/ext/libxml/ruby_libxml.h +75 -0
- data/ext/libxml/ruby_xml.c +977 -0
- data/ext/libxml/ruby_xml.h +20 -0
- data/ext/libxml/ruby_xml_attr.c +333 -0
- data/ext/libxml/ruby_xml_attr.h +12 -0
- data/ext/libxml/ruby_xml_attr_decl.c +153 -0
- data/ext/libxml/ruby_xml_attr_decl.h +11 -0
- data/ext/libxml/ruby_xml_attributes.c +275 -0
- data/ext/libxml/ruby_xml_attributes.h +15 -0
- data/ext/libxml/ruby_xml_cbg.c +85 -0
- data/ext/libxml/ruby_xml_document.c +1133 -0
- data/ext/libxml/ruby_xml_document.h +11 -0
- data/ext/libxml/ruby_xml_dtd.c +261 -0
- data/ext/libxml/ruby_xml_dtd.h +9 -0
- data/ext/libxml/ruby_xml_encoding.c +262 -0
- data/ext/libxml/ruby_xml_encoding.h +19 -0
- data/ext/libxml/ruby_xml_error.c +996 -0
- data/ext/libxml/ruby_xml_error.h +12 -0
- data/ext/libxml/ruby_xml_html_parser.c +92 -0
- data/ext/libxml/ruby_xml_html_parser.h +10 -0
- data/ext/libxml/ruby_xml_html_parser_context.c +337 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +10 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +46 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +10 -0
- data/ext/libxml/ruby_xml_input_cbg.c +191 -0
- data/ext/libxml/ruby_xml_input_cbg.h +20 -0
- data/ext/libxml/ruby_xml_io.c +52 -0
- data/ext/libxml/ruby_xml_io.h +10 -0
- data/ext/libxml/ruby_xml_namespace.c +153 -0
- data/ext/libxml/ruby_xml_namespace.h +10 -0
- data/ext/libxml/ruby_xml_namespaces.c +293 -0
- data/ext/libxml/ruby_xml_namespaces.h +9 -0
- data/ext/libxml/ruby_xml_node.c +1446 -0
- data/ext/libxml/ruby_xml_node.h +11 -0
- data/ext/libxml/ruby_xml_parser.c +94 -0
- data/ext/libxml/ruby_xml_parser.h +12 -0
- data/ext/libxml/ruby_xml_parser_context.c +999 -0
- data/ext/libxml/ruby_xml_parser_context.h +10 -0
- data/ext/libxml/ruby_xml_parser_options.c +66 -0
- data/ext/libxml/ruby_xml_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_reader.c +1226 -0
- data/ext/libxml/ruby_xml_reader.h +17 -0
- data/ext/libxml/ruby_xml_relaxng.c +110 -0
- data/ext/libxml/ruby_xml_relaxng.h +10 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -0
- data/ext/libxml/ruby_xml_sax2_handler.h +10 -0
- data/ext/libxml/ruby_xml_sax_parser.c +120 -0
- data/ext/libxml/ruby_xml_sax_parser.h +10 -0
- data/ext/libxml/ruby_xml_schema.c +300 -0
- data/ext/libxml/ruby_xml_schema.h +809 -0
- data/ext/libxml/ruby_xml_schema_attribute.c +109 -0
- data/ext/libxml/ruby_xml_schema_attribute.h +15 -0
- data/ext/libxml/ruby_xml_schema_element.c +94 -0
- data/ext/libxml/ruby_xml_schema_element.h +14 -0
- data/ext/libxml/ruby_xml_schema_facet.c +52 -0
- data/ext/libxml/ruby_xml_schema_facet.h +13 -0
- data/ext/libxml/ruby_xml_schema_type.c +259 -0
- data/ext/libxml/ruby_xml_schema_type.h +9 -0
- data/ext/libxml/ruby_xml_version.h +9 -0
- data/ext/libxml/ruby_xml_writer.c +1136 -0
- data/ext/libxml/ruby_xml_writer.h +10 -0
- data/ext/libxml/ruby_xml_xinclude.c +16 -0
- data/ext/libxml/ruby_xml_xinclude.h +11 -0
- data/ext/libxml/ruby_xml_xpath.c +188 -0
- data/ext/libxml/ruby_xml_xpath.h +13 -0
- data/ext/libxml/ruby_xml_xpath_context.c +360 -0
- data/ext/libxml/ruby_xml_xpath_context.h +9 -0
- data/ext/libxml/ruby_xml_xpath_expression.c +81 -0
- data/ext/libxml/ruby_xml_xpath_expression.h +10 -0
- data/ext/libxml/ruby_xml_xpath_object.c +335 -0
- data/ext/libxml/ruby_xml_xpath_object.h +17 -0
- data/ext/libxml/ruby_xml_xpointer.c +99 -0
- data/ext/libxml/ruby_xml_xpointer.h +11 -0
- data/ext/vc/libxml_ruby.sln +26 -0
- data/lib/2.3/libxml_ruby.so +0 -0
- data/lib/libs/libiconv-2.dll +0 -0
- data/lib/libs/libxml2-2.dll +0 -0
- data/lib/libs/zlib1.dll +0 -0
- data/lib/libxml.rb +35 -0
- data/lib/libxml/attr.rb +123 -0
- data/lib/libxml/attr_decl.rb +80 -0
- data/lib/libxml/attributes.rb +14 -0
- data/lib/libxml/document.rb +194 -0
- data/lib/libxml/error.rb +95 -0
- data/lib/libxml/hpricot.rb +78 -0
- data/lib/libxml/html_parser.rb +96 -0
- data/lib/libxml/namespace.rb +62 -0
- data/lib/libxml/namespaces.rb +38 -0
- data/lib/libxml/node.rb +399 -0
- data/lib/libxml/ns.rb +22 -0
- data/lib/libxml/parser.rb +367 -0
- data/lib/libxml/properties.rb +23 -0
- data/lib/libxml/reader.rb +29 -0
- data/lib/libxml/sax_callbacks.rb +180 -0
- data/lib/libxml/sax_parser.rb +58 -0
- data/lib/libxml/schema.rb +67 -0
- data/lib/libxml/schema/attribute.rb +19 -0
- data/lib/libxml/schema/element.rb +27 -0
- data/lib/libxml/schema/type.rb +29 -0
- data/lib/libxml/tree.rb +29 -0
- data/lib/libxml/xpath_object.rb +16 -0
- data/lib/xml.rb +14 -0
- data/lib/xml/libxml.rb +10 -0
- data/libxml-ruby.gemspec +47 -0
- data/script/benchmark/depixelate +634 -0
- data/script/benchmark/hamlet.xml +9055 -0
- data/script/benchmark/parsecount +170 -0
- data/script/benchmark/sock_entries.xml +507 -0
- data/script/benchmark/throughput +41 -0
- data/script/test +6 -0
- data/setup.rb +1585 -0
- data/test/c14n/given/doc.dtd +1 -0
- data/test/c14n/given/example-1.xml +14 -0
- data/test/c14n/given/example-2.xml +11 -0
- data/test/c14n/given/example-3.xml +18 -0
- data/test/c14n/given/example-4.xml +9 -0
- data/test/c14n/given/example-5.xml +12 -0
- data/test/c14n/given/example-6.xml +2 -0
- data/test/c14n/given/example-7.xml +11 -0
- data/test/c14n/given/example-8.xml +11 -0
- data/test/c14n/given/example-8.xpath +10 -0
- data/test/c14n/given/world.txt +1 -0
- data/test/c14n/result/1-1-without-comments/example-1 +4 -0
- data/test/c14n/result/1-1-without-comments/example-2 +11 -0
- data/test/c14n/result/1-1-without-comments/example-3 +14 -0
- data/test/c14n/result/1-1-without-comments/example-4 +9 -0
- data/test/c14n/result/1-1-without-comments/example-5 +3 -0
- data/test/c14n/result/1-1-without-comments/example-6 +1 -0
- data/test/c14n/result/1-1-without-comments/example-7 +1 -0
- data/test/c14n/result/1-1-without-comments/example-8 +1 -0
- data/test/c14n/result/with-comments/example-1 +6 -0
- data/test/c14n/result/with-comments/example-2 +11 -0
- data/test/c14n/result/with-comments/example-3 +14 -0
- data/test/c14n/result/with-comments/example-4 +9 -0
- data/test/c14n/result/with-comments/example-5 +4 -0
- data/test/c14n/result/with-comments/example-6 +1 -0
- data/test/c14n/result/with-comments/example-7 +1 -0
- data/test/c14n/result/without-comments/example-1 +4 -0
- data/test/c14n/result/without-comments/example-2 +11 -0
- data/test/c14n/result/without-comments/example-3 +14 -0
- data/test/c14n/result/without-comments/example-4 +9 -0
- data/test/c14n/result/without-comments/example-5 +3 -0
- data/test/c14n/result/without-comments/example-6 +1 -0
- data/test/c14n/result/without-comments/example-7 +1 -0
- data/test/model/atom.xml +13 -0
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/model/bands.xml +5 -0
- data/test/model/books.xml +154 -0
- data/test/model/merge_bug_data.xml +58 -0
- data/test/model/ruby-lang.html +238 -0
- data/test/model/rubynet.xml +79 -0
- data/test/model/rubynet_project +1 -0
- data/test/model/shiporder.rnc +28 -0
- data/test/model/shiporder.rng +86 -0
- data/test/model/shiporder.xml +23 -0
- data/test/model/shiporder.xsd +40 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/tc_attr.rb +181 -0
- data/test/tc_attr_decl.rb +132 -0
- data/test/tc_attributes.rb +142 -0
- data/test/tc_canonicalize.rb +124 -0
- data/test/tc_deprecated_require.rb +12 -0
- data/test/tc_document.rb +125 -0
- data/test/tc_document_write.rb +195 -0
- data/test/tc_dtd.rb +128 -0
- data/test/tc_encoding.rb +126 -0
- data/test/tc_encoding_sax.rb +115 -0
- data/test/tc_error.rb +179 -0
- data/test/tc_html_parser.rb +161 -0
- data/test/tc_html_parser_context.rb +23 -0
- data/test/tc_namespace.rb +61 -0
- data/test/tc_namespaces.rb +209 -0
- data/test/tc_node.rb +215 -0
- data/test/tc_node_cdata.rb +50 -0
- data/test/tc_node_comment.rb +32 -0
- data/test/tc_node_copy.rb +41 -0
- data/test/tc_node_edit.rb +174 -0
- data/test/tc_node_pi.rb +39 -0
- data/test/tc_node_text.rb +70 -0
- data/test/tc_node_write.rb +107 -0
- data/test/tc_node_xlink.rb +28 -0
- data/test/tc_parser.rb +375 -0
- data/test/tc_parser_context.rb +204 -0
- data/test/tc_properties.rb +38 -0
- data/test/tc_reader.rb +399 -0
- data/test/tc_relaxng.rb +53 -0
- data/test/tc_sax_parser.rb +319 -0
- data/test/tc_schema.rb +161 -0
- data/test/tc_traversal.rb +152 -0
- data/test/tc_writer.rb +447 -0
- data/test/tc_xinclude.rb +20 -0
- data/test/tc_xml.rb +225 -0
- data/test/tc_xpath.rb +244 -0
- data/test/tc_xpath_context.rb +88 -0
- data/test/tc_xpath_expression.rb +37 -0
- data/test/tc_xpointer.rb +72 -0
- data/test/test_helper.rb +16 -0
- data/test/test_suite.rb +49 -0
- metadata +344 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#include "ruby_libxml.h"
|
4
|
+
#include "ruby_xml_xpointer.h"
|
5
|
+
|
6
|
+
VALUE cXMLXPointer;
|
7
|
+
|
8
|
+
/*
|
9
|
+
* Document-class: LibXML::XML::XPointer
|
10
|
+
*
|
11
|
+
* The XML::Pointer class provides a standards based API for searching an xml document.
|
12
|
+
* XPointer is based on the XML Path Language (XML::XPath) and is documented
|
13
|
+
* at http://www.w3.org/TR/WD-xptr.
|
14
|
+
*/
|
15
|
+
|
16
|
+
static VALUE rxml_xpointer_point(VALUE class, VALUE rnode, VALUE xptr_str)
|
17
|
+
{
|
18
|
+
#ifdef LIBXML_XPTR_ENABLED
|
19
|
+
xmlNodePtr xnode;
|
20
|
+
xmlXPathContextPtr xctxt;
|
21
|
+
xmlXPathObjectPtr xpop;
|
22
|
+
|
23
|
+
VALUE context;
|
24
|
+
VALUE result;
|
25
|
+
VALUE argv[1];
|
26
|
+
|
27
|
+
Check_Type(xptr_str, T_STRING);
|
28
|
+
if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
|
29
|
+
rb_raise(rb_eTypeError, "require an XML::Node object");
|
30
|
+
|
31
|
+
Data_Get_Struct(rnode, xmlNode, xnode);
|
32
|
+
|
33
|
+
argv[0] = rb_funcall(rnode, rb_intern("doc"), 0);
|
34
|
+
context = rb_class_new_instance(1, argv, cXMLXPathContext);
|
35
|
+
Data_Get_Struct(context, xmlXPathContext, xctxt);
|
36
|
+
|
37
|
+
xpop = xmlXPtrEval((xmlChar*)StringValuePtr(xptr_str), xctxt);
|
38
|
+
if (!xpop)
|
39
|
+
rxml_raise(&xmlLastError);
|
40
|
+
|
41
|
+
result = rxml_xpath_object_wrap(xnode->doc, xpop);
|
42
|
+
rb_iv_set(result, "@context", context);
|
43
|
+
|
44
|
+
return(result);
|
45
|
+
#else
|
46
|
+
rb_warn("libxml was compiled without XPointer support");
|
47
|
+
return (Qfalse);
|
48
|
+
#endif
|
49
|
+
}
|
50
|
+
|
51
|
+
VALUE rxml_xpointer_point2(VALUE node, VALUE xptr_str)
|
52
|
+
{
|
53
|
+
return (rxml_xpointer_point(cXMLXPointer, node, xptr_str));
|
54
|
+
}
|
55
|
+
|
56
|
+
/*
|
57
|
+
* call-seq:
|
58
|
+
* XML::XPointer.range(start_node, end_node) -> xpath
|
59
|
+
*
|
60
|
+
* Create an xpath representing the range between the supplied
|
61
|
+
* start and end node.
|
62
|
+
*/
|
63
|
+
static VALUE rxml_xpointer_range(VALUE class, VALUE rstart, VALUE rend)
|
64
|
+
{
|
65
|
+
#ifdef LIBXML_XPTR_ENABLED
|
66
|
+
xmlNodePtr start, end;
|
67
|
+
VALUE rxxp;
|
68
|
+
xmlXPathObjectPtr xpath;
|
69
|
+
|
70
|
+
if (rb_obj_is_kind_of(rstart, cXMLNode) == Qfalse)
|
71
|
+
rb_raise(rb_eTypeError, "require an XML::Node object as a starting point");
|
72
|
+
if (rb_obj_is_kind_of(rend, cXMLNode) == Qfalse)
|
73
|
+
rb_raise(rb_eTypeError, "require an XML::Node object as an ending point");
|
74
|
+
|
75
|
+
Data_Get_Struct(rstart, xmlNode, start);
|
76
|
+
if (start == NULL)
|
77
|
+
return(Qnil);
|
78
|
+
|
79
|
+
Data_Get_Struct(rend, xmlNode, end);
|
80
|
+
if (end == NULL)
|
81
|
+
return(Qnil);
|
82
|
+
|
83
|
+
xpath = xmlXPtrNewRangeNodes(start, end);
|
84
|
+
if (xpath == NULL)
|
85
|
+
rb_fatal("You shouldn't be able to have this happen");
|
86
|
+
|
87
|
+
rxxp = rxml_xpath_object_wrap(start->doc, xpath);
|
88
|
+
return(rxxp);
|
89
|
+
#else
|
90
|
+
rb_warn("libxml was compiled without XPointer support");
|
91
|
+
return (Qfalse);
|
92
|
+
#endif
|
93
|
+
}
|
94
|
+
|
95
|
+
void rxml_init_xpointer(void)
|
96
|
+
{
|
97
|
+
cXMLXPointer = rb_define_class_under(mXML, "XPointer", rb_cObject);
|
98
|
+
rb_define_singleton_method(cXMLXPointer, "range", rxml_xpointer_range, 2);
|
99
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RXML_XPOINTER__
|
4
|
+
#define __RXML_XPOINTER__
|
5
|
+
|
6
|
+
extern VALUE cXMLXPointer;
|
7
|
+
|
8
|
+
void rxml_init_xpointer(void);
|
9
|
+
VALUE rxml_xpointer_point2(VALUE node, VALUE xptr_str);
|
10
|
+
|
11
|
+
#endif
|
@@ -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
|
Binary file
|
data/lib/libs/zlib1.dll
ADDED
Binary file
|
data/lib/libxml.rb
ADDED
@@ -0,0 +1,35 @@
|
|
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
|
+
# Load Ruby supporting code.
|
11
|
+
require 'libxml/error'
|
12
|
+
require 'libxml/parser'
|
13
|
+
require 'libxml/document'
|
14
|
+
require 'libxml/namespaces'
|
15
|
+
require 'libxml/namespace'
|
16
|
+
require 'libxml/node'
|
17
|
+
require 'libxml/ns'
|
18
|
+
require 'libxml/attributes'
|
19
|
+
require 'libxml/attr'
|
20
|
+
require 'libxml/attr_decl'
|
21
|
+
require 'libxml/tree'
|
22
|
+
require 'libxml/reader'
|
23
|
+
require 'libxml/html_parser'
|
24
|
+
require 'libxml/sax_parser'
|
25
|
+
require 'libxml/sax_callbacks'
|
26
|
+
require 'libxml/xpath_object'
|
27
|
+
|
28
|
+
#Schema Interface
|
29
|
+
require 'libxml/schema'
|
30
|
+
require 'libxml/schema/type'
|
31
|
+
require 'libxml/schema/element'
|
32
|
+
require 'libxml/schema/attribute'
|
33
|
+
|
34
|
+
# Deprecated
|
35
|
+
require 'libxml/properties'
|
data/lib/libxml/attr.rb
ADDED
@@ -0,0 +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
|
123
|
+
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,194 @@
|
|
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) -> XML::Document
|
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
|
+
# call-seq:
|
99
|
+
# document.find(xpath, nslist=nil) -> XML::XPath::Object
|
100
|
+
#
|
101
|
+
# Parameters:
|
102
|
+
# * xpath - The xpath expression as a string
|
103
|
+
# * namespaces - An optional list of namespaces (see XML::XPath for information).
|
104
|
+
#
|
105
|
+
# document.find('/foo', 'xlink:http://www.w3.org/1999/xlink')
|
106
|
+
#
|
107
|
+
# IMPORTANT - The returned XML::Node::Set must be freed before
|
108
|
+
# its associated document. In a running Ruby program this will
|
109
|
+
# happen automatically via Ruby's mark and sweep garbage collector.
|
110
|
+
# However, if the program exits, Ruby does not guarantee the order
|
111
|
+
# in which objects are freed
|
112
|
+
# (see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/17700).
|
113
|
+
# As a result, the associated document may be freed before the node
|
114
|
+
# list, which will cause a segmentation fault.
|
115
|
+
# To avoid this, use the following (non-ruby like) coding style:
|
116
|
+
#
|
117
|
+
# nodes = doc.find('/header')
|
118
|
+
# nodes.each do |node|
|
119
|
+
# ... do stuff ...
|
120
|
+
# end
|
121
|
+
# # nodes = nil # GC.start
|
122
|
+
def find(xpath, nslist = nil)
|
123
|
+
self.context(nslist).find(xpath)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Return the first node matching the specified xpath expression.
|
127
|
+
# For more information, please refer to the documentation
|
128
|
+
# for XML::Document#find.
|
129
|
+
def find_first(xpath, nslist = nil)
|
130
|
+
find(xpath, nslist).first
|
131
|
+
end
|
132
|
+
|
133
|
+
# Returns this node's type name
|
134
|
+
def node_type_name
|
135
|
+
case node_type
|
136
|
+
when XML::Node::DOCUMENT_NODE
|
137
|
+
'document_xml'
|
138
|
+
when XML::Node::DOCB_DOCUMENT_NODE
|
139
|
+
'document_docbook'
|
140
|
+
when XML::Node::HTML_DOCUMENT_NODE
|
141
|
+
'document_html'
|
142
|
+
else
|
143
|
+
raise(UnknownType, "Unknown node type: %n", node.node_type);
|
144
|
+
end
|
145
|
+
end
|
146
|
+
# :enddoc:
|
147
|
+
|
148
|
+
# Specifies if this is an document node
|
149
|
+
def document?
|
150
|
+
node_type == XML::Node::DOCUMENT_NODE
|
151
|
+
end
|
152
|
+
|
153
|
+
# Specifies if this is an docbook node
|
154
|
+
def docbook_doc?
|
155
|
+
node_type == XML::Node::DOCB_DOCUMENT_NODE
|
156
|
+
end
|
157
|
+
|
158
|
+
# Specifies if this is an html node
|
159
|
+
def html_doc?
|
160
|
+
node_type == XML::Node::HTML_DOCUMENT_NODE
|
161
|
+
end
|
162
|
+
|
163
|
+
def dump
|
164
|
+
warn('Document#dump is deprecated. Use Document#to_s instead.')
|
165
|
+
self.to_s
|
166
|
+
end
|
167
|
+
|
168
|
+
def format_dump
|
169
|
+
warn('Document#format_dump is deprecated. Use Document#to_s instead.')
|
170
|
+
self.to_s
|
171
|
+
end
|
172
|
+
|
173
|
+
def debug_dump
|
174
|
+
warn('Document#debug_dump is deprecated. Use Document#debug instead.')
|
175
|
+
self.debug
|
176
|
+
end
|
177
|
+
|
178
|
+
def debug_dump_head
|
179
|
+
warn('Document#debug_dump_head is deprecated. Use Document#debug instead.')
|
180
|
+
self.debug
|
181
|
+
end
|
182
|
+
|
183
|
+
def debug_format_dump
|
184
|
+
warn('Document#debug_format_dump is deprecated. Use Document#to_s instead.')
|
185
|
+
self.to_s
|
186
|
+
end
|
187
|
+
|
188
|
+
def reader
|
189
|
+
warn('Document#reader is deprecated. Use XML::Reader.document(self) instead.')
|
190
|
+
XML::Reader.document(self)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|