coupa-libxml-ruby 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +488 -0
- data/LICENSE +22 -0
- data/README +161 -0
- data/Rakefile +188 -0
- data/doc/css/normal.css +182 -0
- data/doc/img/raze-tiny.png +0 -0
- data/doc/img/red-cube.jpg +0 -0
- data/doc/img/xml-ruby.png +0 -0
- data/doc/index.xml +43 -0
- data/doc/install.xml +77 -0
- data/doc/layout.rhtml +38 -0
- data/doc/layout.xsl +67 -0
- data/doc/license.xml +32 -0
- data/doc/log/changelog.xml +1324 -0
- data/doc/log/changelog.xsl +42 -0
- data/doc/rdoc/classes/LibXML.html +207 -0
- data/doc/rdoc/classes/LibXML/XML.html +407 -0
- data/doc/rdoc/classes/LibXML/XML/Attr.html +521 -0
- data/doc/rdoc/classes/LibXML/XML/AttrDecl.html +360 -0
- data/doc/rdoc/classes/LibXML/XML/Attributes.html +149 -0
- data/doc/rdoc/classes/LibXML/XML/Document.html +460 -0
- data/doc/rdoc/classes/LibXML/XML/Error.html +129 -0
- data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +263 -0
- data/doc/rdoc/classes/LibXML/XML/Namespace.html +248 -0
- data/doc/rdoc/classes/LibXML/XML/Namespaces.html +200 -0
- data/doc/rdoc/classes/LibXML/XML/Node.html +1351 -0
- data/doc/rdoc/classes/LibXML/XML/Parser.html +328 -0
- data/doc/rdoc/classes/LibXML/XML/Reader.html +172 -0
- data/doc/rdoc/classes/LibXML/XML/SaxParser.html +232 -0
- data/doc/rdoc/classes/LibXML/XML/SaxParser/Callbacks.html +506 -0
- data/doc/rdoc/classes/LibXML/XML/SaxParser/VerboseCallbacks.html +555 -0
- data/doc/rdoc/classes/LibXML/XML/XPath.html +111 -0
- data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +162 -0
- data/doc/rdoc/classes/cXMLDtd.html +114 -0
- data/doc/rdoc/classes/cXMLNode.html +114 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/CHANGES.html +794 -0
- data/doc/rdoc/files/LICENSE.html +131 -0
- data/doc/rdoc/files/README.html +343 -0
- data/doc/rdoc/files/ext/libxml/libxml_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_attr_decl_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_cbg_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_encoding_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_error_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_context_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_options_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_io_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_namespace_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_namespaces_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_options_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_sax2_handler_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_expression_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +101 -0
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +101 -0
- data/doc/rdoc/files/lib/libxml/attr_decl_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/attr_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/attributes_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/document_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/error_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/hpricot_rb.html +192 -0
- data/doc/rdoc/files/lib/libxml/html_parser_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/namespace_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/namespaces_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/node_rb.html +108 -0
- data/doc/rdoc/files/lib/libxml/ns_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/parser_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/properties_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/reader_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/sax_callbacks_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/sax_parser_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/tree_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml/xpath_object_rb.html +101 -0
- data/doc/rdoc/files/lib/libxml_rb.html +133 -0
- data/doc/rdoc/files/lib/xml/libxml_rb.html +124 -0
- data/doc/rdoc/files/lib/xml_rb.html +134 -0
- data/doc/rdoc/fr_class_index.html +46 -0
- data/doc/rdoc/fr_file_index.html +84 -0
- data/doc/rdoc/fr_method_index.html +155 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/ext/libxml/Makefile +157 -0
- data/ext/libxml/build.log +4 -0
- data/ext/libxml/extconf.h +5 -0
- data/ext/libxml/extconf.rb +278 -0
- data/ext/libxml/libxml.c +77 -0
- data/ext/libxml/libxml.o +0 -0
- data/ext/libxml/libxml_ruby.bundle +0 -0
- data/ext/libxml/mkmf.log +228 -0
- data/ext/libxml/ruby_libxml.h +93 -0
- data/ext/libxml/ruby_xml.c +893 -0
- data/ext/libxml/ruby_xml.h +10 -0
- data/ext/libxml/ruby_xml.o +0 -0
- data/ext/libxml/ruby_xml_attr.c +352 -0
- data/ext/libxml/ruby_xml_attr.h +14 -0
- data/ext/libxml/ruby_xml_attr.o +0 -0
- data/ext/libxml/ruby_xml_attr_decl.c +171 -0
- data/ext/libxml/ruby_xml_attr_decl.h +13 -0
- data/ext/libxml/ruby_xml_attr_decl.o +0 -0
- data/ext/libxml/ruby_xml_attributes.c +277 -0
- data/ext/libxml/ruby_xml_attributes.h +17 -0
- data/ext/libxml/ruby_xml_attributes.o +0 -0
- data/ext/libxml/ruby_xml_cbg.c +86 -0
- data/ext/libxml/ruby_xml_cbg.o +0 -0
- data/ext/libxml/ruby_xml_document.c +1006 -0
- data/ext/libxml/ruby_xml_document.c.old +936 -0
- data/ext/libxml/ruby_xml_document.h +17 -0
- data/ext/libxml/ruby_xml_document.o +0 -0
- data/ext/libxml/ruby_xml_dtd.c +257 -0
- data/ext/libxml/ruby_xml_dtd.h +9 -0
- data/ext/libxml/ruby_xml_dtd.o +0 -0
- data/ext/libxml/ruby_xml_encoding.c +134 -0
- data/ext/libxml/ruby_xml_encoding.h +12 -0
- data/ext/libxml/ruby_xml_encoding.o +0 -0
- data/ext/libxml/ruby_xml_error.c +1004 -0
- data/ext/libxml/ruby_xml_error.h +14 -0
- data/ext/libxml/ruby_xml_error.o +0 -0
- data/ext/libxml/ruby_xml_html_parser.c +92 -0
- data/ext/libxml/ruby_xml_html_parser.h +12 -0
- data/ext/libxml/ruby_xml_html_parser.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_options.o +0 -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_input_cbg.o +0 -0
- data/ext/libxml/ruby_xml_io.c +30 -0
- data/ext/libxml/ruby_xml_io.h +9 -0
- data/ext/libxml/ruby_xml_io.o +0 -0
- data/ext/libxml/ruby_xml_namespace.c +170 -0
- data/ext/libxml/ruby_xml_namespace.h +12 -0
- data/ext/libxml/ruby_xml_namespace.o +0 -0
- data/ext/libxml/ruby_xml_namespaces.c +295 -0
- data/ext/libxml/ruby_xml_namespaces.h +11 -0
- data/ext/libxml/ruby_xml_namespaces.o +0 -0
- data/ext/libxml/ruby_xml_node.c +1386 -0
- data/ext/libxml/ruby_xml_node.h +13 -0
- data/ext/libxml/ruby_xml_node.o +0 -0
- data/ext/libxml/ruby_xml_parser.c +94 -0
- data/ext/libxml/ruby_xml_parser.h +14 -0
- data/ext/libxml/ruby_xml_parser.o +0 -0
- data/ext/libxml/ruby_xml_parser_context.c +982 -0
- data/ext/libxml/ruby_xml_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_parser_options.c +68 -0
- data/ext/libxml/ruby_xml_parser_options.h +14 -0
- data/ext/libxml/ruby_xml_parser_options.o +0 -0
- data/ext/libxml/ruby_xml_reader.c +1002 -0
- data/ext/libxml/ruby_xml_reader.h +14 -0
- data/ext/libxml/ruby_xml_reader.o +0 -0
- data/ext/libxml/ruby_xml_relaxng.c +111 -0
- data/ext/libxml/ruby_xml_relaxng.h +10 -0
- data/ext/libxml/ruby_xml_relaxng.o +0 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +322 -0
- data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
- data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
- data/ext/libxml/ruby_xml_sax_parser.c +137 -0
- data/ext/libxml/ruby_xml_sax_parser.h +12 -0
- data/ext/libxml/ruby_xml_sax_parser.o +0 -0
- data/ext/libxml/ruby_xml_schema.c +159 -0
- data/ext/libxml/ruby_xml_schema.h +11 -0
- data/ext/libxml/ruby_xml_schema.o +0 -0
- data/ext/libxml/ruby_xml_version.h +9 -0
- data/ext/libxml/ruby_xml_xinclude.c +18 -0
- data/ext/libxml/ruby_xml_xinclude.h +13 -0
- data/ext/libxml/ruby_xml_xinclude.o +0 -0
- data/ext/libxml/ruby_xml_xpath.c +107 -0
- data/ext/libxml/ruby_xml_xpath.h +12 -0
- data/ext/libxml/ruby_xml_xpath.o +0 -0
- data/ext/libxml/ruby_xml_xpath_context.c +387 -0
- data/ext/libxml/ruby_xml_xpath_context.h +11 -0
- data/ext/libxml/ruby_xml_xpath_context.o +0 -0
- data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
- data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
- data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
- data/ext/libxml/ruby_xml_xpath_object.c +336 -0
- data/ext/libxml/ruby_xml_xpath_object.h +19 -0
- data/ext/libxml/ruby_xml_xpath_object.o +0 -0
- data/ext/libxml/ruby_xml_xpointer.c +101 -0
- data/ext/libxml/ruby_xml_xpointer.h +13 -0
- data/ext/libxml/ruby_xml_xpointer.o +0 -0
- data/ext/mingw/Rakefile +34 -0
- data/ext/mingw/build.rake +41 -0
- data/ext/vc/libxml_ruby.sln +26 -0
- data/lib/libxml.rb +30 -0
- data/lib/libxml/attr.rb +111 -0
- data/lib/libxml/attr_decl.rb +78 -0
- data/lib/libxml/attributes.rb +12 -0
- data/lib/libxml/document.rb +190 -0
- data/lib/libxml/error.rb +88 -0
- data/lib/libxml/hpricot.rb +76 -0
- data/lib/libxml/html_parser.rb +94 -0
- data/lib/libxml/namespace.rb +60 -0
- data/lib/libxml/namespaces.rb +36 -0
- data/lib/libxml/node.rb +385 -0
- data/lib/libxml/ns.rb +20 -0
- data/lib/libxml/parser.rb +365 -0
- data/lib/libxml/properties.rb +21 -0
- data/lib/libxml/reader.rb +27 -0
- data/lib/libxml/sax_callbacks.rb +178 -0
- data/lib/libxml/sax_parser.rb +56 -0
- data/lib/libxml/tree.rb +27 -0
- data/lib/libxml/xpath_object.rb +14 -0
- data/lib/xml.rb +14 -0
- data/lib/xml/libxml.rb +8 -0
- data/setup.rb +1585 -0
- data/test/etc_doc_to_s.rb +19 -0
- data/test/ets_doc_file.rb +15 -0
- data/test/ets_doc_to_s.rb +21 -0
- data/test/ets_gpx.rb +26 -0
- data/test/ets_node_gc.rb +21 -0
- data/test/ets_test.xml +2 -0
- data/test/ets_tsr.rb +9 -0
- data/test/model/atom.xml +13 -0
- data/test/model/bands.xml +5 -0
- data/test/model/books.xml +146 -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 +31 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/tc_attr.rb +170 -0
- data/test/tc_attr_decl.rb +131 -0
- data/test/tc_attributes.rb +133 -0
- data/test/tc_deprecated_require.rb +11 -0
- data/test/tc_document.rb +113 -0
- data/test/tc_document_write.rb +118 -0
- data/test/tc_dtd.rb +123 -0
- data/test/tc_error.rb +136 -0
- data/test/tc_html_parser.rb +138 -0
- data/test/tc_namespace.rb +59 -0
- data/test/tc_namespaces.rb +174 -0
- data/test/tc_node.rb +181 -0
- data/test/tc_node_cdata.rb +49 -0
- data/test/tc_node_comment.rb +30 -0
- data/test/tc_node_copy.rb +40 -0
- data/test/tc_node_edit.rb +158 -0
- data/test/tc_node_text.rb +69 -0
- data/test/tc_node_write.rb +83 -0
- data/test/tc_node_xlink.rb +26 -0
- data/test/tc_parser.rb +330 -0
- data/test/tc_parser_context.rb +186 -0
- data/test/tc_properties.rb +36 -0
- data/test/tc_reader.rb +284 -0
- data/test/tc_relaxng.rb +51 -0
- data/test/tc_sax_parser.rb +274 -0
- data/test/tc_schema.rb +51 -0
- data/test/tc_traversal.rb +220 -0
- data/test/tc_xinclude.rb +19 -0
- data/test/tc_xml.rb +224 -0
- data/test/tc_xpath.rb +193 -0
- data/test/tc_xpath_context.rb +78 -0
- data/test/tc_xpath_expression.rb +35 -0
- data/test/tc_xpointer.rb +72 -0
- data/test/test_suite.rb +33 -0
- metadata +376 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
/* $Id: ruby_xml_xpath.h 758 2009-01-25 20:36:03Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RXML_XPATH__
|
6
|
+
#define __RXML_XPATH__
|
7
|
+
|
8
|
+
extern VALUE mXPath;
|
9
|
+
|
10
|
+
void rxml_init_xpath(void);
|
11
|
+
|
12
|
+
#endif
|
Binary file
|
@@ -0,0 +1,387 @@
|
|
1
|
+
/* $Id: ruby_xml_xpath_context.c 799 2009-03-02 01:45:24Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "ruby_libxml.h"
|
6
|
+
#include "ruby_xml_xpath_context.h"
|
7
|
+
#include "ruby_xml_xpath_expression.h"
|
8
|
+
|
9
|
+
#if RUBY_ST_H
|
10
|
+
#include <ruby/st.h>
|
11
|
+
#else
|
12
|
+
#include <st.h>
|
13
|
+
#endif
|
14
|
+
|
15
|
+
/*
|
16
|
+
* Document-class: LibXML::XML::XPath::Context
|
17
|
+
*
|
18
|
+
* The XML::XPath::Context class is used to evaluate XPath
|
19
|
+
* expressions. Generally, you should not directly use this class,
|
20
|
+
* but instead use the XML::Document#find and XML::Node#find methods.
|
21
|
+
*
|
22
|
+
* doc = XML::Document.string('<header>content</header>')
|
23
|
+
* context = XPath::Context.new(doc)
|
24
|
+
* context.node = doc.root
|
25
|
+
* context.register_namespaces_from_node(doc.root)
|
26
|
+
* nodes = context.find('/header')
|
27
|
+
*/
|
28
|
+
|
29
|
+
VALUE cXMLXPathContext;
|
30
|
+
|
31
|
+
static ID DOC_ATTRIBUTE;
|
32
|
+
|
33
|
+
static void rxml_xpath_context_free(xmlXPathContextPtr ctxt)
|
34
|
+
{
|
35
|
+
xmlXPathFreeContext(ctxt);
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE rxml_xpath_context_alloc(VALUE klass)
|
39
|
+
{
|
40
|
+
return Data_Wrap_Struct(cXMLXPathContext, NULL, rxml_xpath_context_free, NULL);
|
41
|
+
}
|
42
|
+
|
43
|
+
/* call-seq:
|
44
|
+
* XPath::Context.new(node) -> XPath::Context
|
45
|
+
*
|
46
|
+
* Creates a new XPath context for the specified document. The
|
47
|
+
* context can then be used to evaluate an XPath expression.
|
48
|
+
*
|
49
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
50
|
+
* context = XPath::Context.new(doc)
|
51
|
+
* nodes = XPath::Object.new('//first', context)
|
52
|
+
* nodes.length == 1
|
53
|
+
*/
|
54
|
+
static VALUE rxml_xpath_context_initialize(VALUE self, VALUE node)
|
55
|
+
{
|
56
|
+
xmlDocPtr xdoc;
|
57
|
+
VALUE document;
|
58
|
+
|
59
|
+
if (rb_obj_is_kind_of(node, cXMLNode) == Qtrue)
|
60
|
+
{
|
61
|
+
document = rb_funcall(node, rb_intern("doc"), 0);
|
62
|
+
if (NIL_P(document))
|
63
|
+
rb_raise(rb_eTypeError, "Supplied node must belong to a document.");
|
64
|
+
}
|
65
|
+
else if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
|
66
|
+
{
|
67
|
+
document = node;
|
68
|
+
}
|
69
|
+
else
|
70
|
+
{
|
71
|
+
rb_raise(rb_eTypeError, "Supplied argument must be a document or node.");
|
72
|
+
}
|
73
|
+
|
74
|
+
Data_Get_Struct(document, xmlDoc, xdoc);
|
75
|
+
DATA_PTR(self) = xmlXPathNewContext(xdoc);
|
76
|
+
|
77
|
+
/* Save the doc as an attribute, this will expose it to Ruby's GC. */
|
78
|
+
rb_ivar_set(self, DOC_ATTRIBUTE, document);
|
79
|
+
|
80
|
+
return self;
|
81
|
+
}
|
82
|
+
|
83
|
+
/*
|
84
|
+
* call-seq:
|
85
|
+
* context.register_namespace(prefix, uri) -> (true|false)
|
86
|
+
*
|
87
|
+
* Register the specified namespace URI with the specified prefix
|
88
|
+
* in this context.
|
89
|
+
|
90
|
+
* context.register_namespace('xi', 'http://www.w3.org/2001/XInclude')
|
91
|
+
*/
|
92
|
+
static VALUE rxml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri)
|
93
|
+
{
|
94
|
+
xmlXPathContextPtr ctxt;
|
95
|
+
Data_Get_Struct(self, xmlXPathContext, ctxt);
|
96
|
+
|
97
|
+
/* Prefix could be a symbol. */
|
98
|
+
prefix = rb_obj_as_string(prefix);
|
99
|
+
|
100
|
+
if (xmlXPathRegisterNs(ctxt, (xmlChar*) StringValuePtr(prefix),
|
101
|
+
(xmlChar*) StringValuePtr(uri)) == 0)
|
102
|
+
{
|
103
|
+
return (Qtrue);
|
104
|
+
}
|
105
|
+
else
|
106
|
+
{
|
107
|
+
/* Should raise an exception, IMHO (whose?, why shouldnt it? -danj)*/
|
108
|
+
rb_warning("register namespace failed");
|
109
|
+
return (Qfalse);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
/* call-seq:
|
114
|
+
* context.register_namespaces_from_node(node) -> self
|
115
|
+
*
|
116
|
+
* Helper method to read in namespaces defined on a node.
|
117
|
+
*
|
118
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
119
|
+
* context = XPath::Context.new(doc)
|
120
|
+
* context.register_namespaces_from_node(doc.root)
|
121
|
+
*/
|
122
|
+
static VALUE rxml_xpath_context_register_namespaces_from_node(VALUE self,
|
123
|
+
VALUE node)
|
124
|
+
{
|
125
|
+
xmlXPathContextPtr xctxt;
|
126
|
+
xmlNodePtr xnode;
|
127
|
+
xmlNsPtr *xnsArr;
|
128
|
+
|
129
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
130
|
+
|
131
|
+
if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
|
132
|
+
{
|
133
|
+
xmlDocPtr xdoc;
|
134
|
+
Data_Get_Struct(node, xmlDoc, xdoc);
|
135
|
+
xnode = xmlDocGetRootElement(xdoc);
|
136
|
+
}
|
137
|
+
else if (rb_obj_is_kind_of(node, cXMLNode) == Qtrue)
|
138
|
+
{
|
139
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
140
|
+
}
|
141
|
+
else
|
142
|
+
{
|
143
|
+
rb_raise(rb_eTypeError, "The first argument must be a document or node.");
|
144
|
+
}
|
145
|
+
|
146
|
+
xnsArr = xmlGetNsList(xnode->doc, xnode);
|
147
|
+
|
148
|
+
if (xnsArr)
|
149
|
+
{
|
150
|
+
xmlNsPtr xns = *xnsArr;
|
151
|
+
|
152
|
+
while (xns)
|
153
|
+
{
|
154
|
+
/* If there is no prefix, then this is the default namespace.
|
155
|
+
Skip it for now. */
|
156
|
+
if (xns->prefix)
|
157
|
+
{
|
158
|
+
VALUE prefix = rb_str_new2((const char*)xns->prefix);
|
159
|
+
VALUE uri = rb_str_new2((const char*)xns->href);
|
160
|
+
rxml_xpath_context_register_namespace(self, prefix, uri);
|
161
|
+
}
|
162
|
+
xns = xns->next;
|
163
|
+
}
|
164
|
+
xmlFree(xnsArr);
|
165
|
+
}
|
166
|
+
|
167
|
+
return self;
|
168
|
+
}
|
169
|
+
|
170
|
+
static int iterate_ns_hash(st_data_t prefix, st_data_t uri, st_data_t self)
|
171
|
+
{
|
172
|
+
rxml_xpath_context_register_namespace(self, prefix, uri);
|
173
|
+
return ST_CONTINUE;
|
174
|
+
}
|
175
|
+
|
176
|
+
/*
|
177
|
+
* call-seq:
|
178
|
+
* context.register_namespaces(["prefix:uri"]) -> self
|
179
|
+
*
|
180
|
+
* Register the specified namespaces in this context. There are
|
181
|
+
* three different forms that libxml accepts. These include
|
182
|
+
* a string, an array of strings, or a hash table:
|
183
|
+
*
|
184
|
+
* context.register_namespaces('xi:http://www.w3.org/2001/XInclude')
|
185
|
+
* context.register_namespaces(['xlink:http://www.w3.org/1999/xlink',
|
186
|
+
* 'xi:http://www.w3.org/2001/XInclude')
|
187
|
+
* context.register_namespaces('xlink' => 'http://www.w3.org/1999/xlink',
|
188
|
+
* 'xi' => 'http://www.w3.org/2001/XInclude')
|
189
|
+
*/
|
190
|
+
static VALUE rxml_xpath_context_register_namespaces(VALUE self, VALUE nslist)
|
191
|
+
{
|
192
|
+
char *cp;
|
193
|
+
long i;
|
194
|
+
VALUE rprefix, ruri;
|
195
|
+
|
196
|
+
/* Need to loop through the 2nd argument and iterate through the
|
197
|
+
* list of namespaces that we want to allow */
|
198
|
+
switch (TYPE(nslist))
|
199
|
+
{
|
200
|
+
case T_STRING:
|
201
|
+
cp = strchr(StringValuePtr(nslist), (int) ':');
|
202
|
+
if (cp == NULL)
|
203
|
+
{
|
204
|
+
rprefix = nslist;
|
205
|
+
ruri = Qnil;
|
206
|
+
}
|
207
|
+
else
|
208
|
+
{
|
209
|
+
rprefix = rb_str_new(StringValuePtr(nslist), (int) ((long) cp
|
210
|
+
- (long) StringValuePtr(nslist)));
|
211
|
+
ruri = rb_str_new2(&cp[1]);
|
212
|
+
}
|
213
|
+
/* Should test the results of this */
|
214
|
+
rxml_xpath_context_register_namespace(self, rprefix, ruri);
|
215
|
+
break;
|
216
|
+
case T_ARRAY:
|
217
|
+
for (i = 0; i < RARRAY_LEN(nslist); i++)
|
218
|
+
{
|
219
|
+
rxml_xpath_context_register_namespaces(self, RARRAY_PTR(nslist)[i]);
|
220
|
+
}
|
221
|
+
break;
|
222
|
+
case T_HASH:
|
223
|
+
st_foreach(RHASH_TBL(nslist), iterate_ns_hash, self);
|
224
|
+
break;
|
225
|
+
default:
|
226
|
+
rb_raise(
|
227
|
+
rb_eArgError,
|
228
|
+
"Invalid argument type, only accept string, array of strings, or an array of arrays");
|
229
|
+
}
|
230
|
+
return self;
|
231
|
+
}
|
232
|
+
|
233
|
+
/*
|
234
|
+
* call-seq:
|
235
|
+
* context.node = node
|
236
|
+
*
|
237
|
+
* Set the current node used by the XPath engine
|
238
|
+
|
239
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
240
|
+
* context.node = doc.root.first
|
241
|
+
*/
|
242
|
+
static VALUE rxml_xpath_context_node_set(VALUE self, VALUE node)
|
243
|
+
{
|
244
|
+
xmlXPathContextPtr xctxt;
|
245
|
+
xmlNodePtr xnode;
|
246
|
+
|
247
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
248
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
249
|
+
xctxt->node = xnode;
|
250
|
+
return node;
|
251
|
+
}
|
252
|
+
|
253
|
+
/*
|
254
|
+
* call-seq:
|
255
|
+
* context.find("xpath") -> true|false|number|string|XML::XPath::Object
|
256
|
+
*
|
257
|
+
* Executes the provided xpath function. The result depends on the execution
|
258
|
+
* of the xpath statement. It may be true, false, a number, a string or
|
259
|
+
* a node set.
|
260
|
+
*/
|
261
|
+
static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr)
|
262
|
+
{
|
263
|
+
xmlXPathContextPtr xctxt;
|
264
|
+
xmlXPathObjectPtr xobject;
|
265
|
+
xmlXPathCompExprPtr xcompexpr;
|
266
|
+
VALUE result;
|
267
|
+
|
268
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
269
|
+
|
270
|
+
if (TYPE(xpath_expr) == T_STRING)
|
271
|
+
{
|
272
|
+
VALUE expression = rb_check_string_type(xpath_expr);
|
273
|
+
xobject = xmlXPathEval((xmlChar*) StringValueCStr(expression), xctxt);
|
274
|
+
}
|
275
|
+
else if (rb_obj_is_kind_of(xpath_expr, cXMLXPathExpression))
|
276
|
+
{
|
277
|
+
Data_Get_Struct(xpath_expr, xmlXPathCompExpr, xcompexpr);
|
278
|
+
xobject = xmlXPathCompiledEval(xcompexpr, xctxt);
|
279
|
+
}
|
280
|
+
else
|
281
|
+
{
|
282
|
+
rb_raise(rb_eTypeError,
|
283
|
+
"Argument should be an intance of a String or XPath::Expression");
|
284
|
+
}
|
285
|
+
|
286
|
+
if (xobject == NULL)
|
287
|
+
{
|
288
|
+
/* xmlLastError is different than xctxt->lastError. Use
|
289
|
+
xmlLastError since it has the message set while xctxt->lastError
|
290
|
+
does not. */
|
291
|
+
xmlErrorPtr xerror = xmlGetLastError();
|
292
|
+
rxml_raise(xerror);
|
293
|
+
}
|
294
|
+
|
295
|
+
switch (xobject->type)
|
296
|
+
{
|
297
|
+
case XPATH_NODESET:
|
298
|
+
result = rxml_xpath_object_wrap(xctxt->doc, xobject);
|
299
|
+
break;
|
300
|
+
case XPATH_BOOLEAN:
|
301
|
+
result = (xobject->boolval != 0) ? Qtrue : Qfalse;
|
302
|
+
xmlXPathFreeObject(xobject);
|
303
|
+
break;
|
304
|
+
case XPATH_NUMBER:
|
305
|
+
result = rb_float_new(xobject->floatval);
|
306
|
+
xmlXPathFreeObject(xobject);
|
307
|
+
break;
|
308
|
+
case XPATH_STRING:
|
309
|
+
result = rb_str_new2((const char*)xobject->stringval);
|
310
|
+
xmlXPathFreeObject(xobject);
|
311
|
+
break;
|
312
|
+
default:
|
313
|
+
result = Qnil;
|
314
|
+
xmlXPathFreeObject(xobject);
|
315
|
+
}
|
316
|
+
return result;
|
317
|
+
}
|
318
|
+
|
319
|
+
#if LIBXML_VERSION >= 20626
|
320
|
+
/*
|
321
|
+
* call-seq:
|
322
|
+
* context.enable_cache(size = nil)
|
323
|
+
*
|
324
|
+
* Enables an XPath::Context's built-in cache. If the cache is
|
325
|
+
* enabled then XPath objects will be cached internally for reuse.
|
326
|
+
* The size parameter controls sets the maximum number of XPath objects
|
327
|
+
* that will be cached per XPath object type (node-set, string, number,
|
328
|
+
* boolean, and misc objects). Set size to nil to use the default
|
329
|
+
* cache size of 100.
|
330
|
+
*/
|
331
|
+
static VALUE
|
332
|
+
rxml_xpath_context_enable_cache(int argc, VALUE *argv, VALUE self)
|
333
|
+
{
|
334
|
+
xmlXPathContextPtr xctxt;
|
335
|
+
VALUE size;
|
336
|
+
int value = -1;
|
337
|
+
|
338
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
339
|
+
|
340
|
+
if (rb_scan_args(argc, argv, "01", &size) == 1)
|
341
|
+
{
|
342
|
+
value = NUM2INT(size);
|
343
|
+
}
|
344
|
+
|
345
|
+
if (xmlXPathContextSetCache(xctxt, 1, value, 0) == -1)
|
346
|
+
rxml_raise(&xmlLastError);
|
347
|
+
|
348
|
+
return self;
|
349
|
+
}
|
350
|
+
|
351
|
+
/*
|
352
|
+
* call-seq:
|
353
|
+
* context.disable_cache
|
354
|
+
*
|
355
|
+
* Disables an XPath::Context's built-in cache.
|
356
|
+
*/
|
357
|
+
static VALUE
|
358
|
+
rxml_xpath_context_disable_cache(VALUE self)
|
359
|
+
{
|
360
|
+
xmlXPathContextPtr xctxt;
|
361
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
362
|
+
|
363
|
+
if (xmlXPathContextSetCache(xctxt, 0, 0, 0) == -1)
|
364
|
+
rxml_raise(&xmlLastError);
|
365
|
+
|
366
|
+
return self;
|
367
|
+
}
|
368
|
+
#endif
|
369
|
+
|
370
|
+
void rxml_init_xpath_context(void)
|
371
|
+
{
|
372
|
+
DOC_ATTRIBUTE = rb_intern("@doc");
|
373
|
+
|
374
|
+
cXMLXPathContext = rb_define_class_under(mXPath, "Context", rb_cObject);
|
375
|
+
rb_define_alloc_func(cXMLXPathContext, rxml_xpath_context_alloc);
|
376
|
+
rb_define_attr(cXMLXPathContext, "doc", 1, 0);
|
377
|
+
rb_define_method(cXMLXPathContext, "initialize", rxml_xpath_context_initialize, 1);
|
378
|
+
rb_define_method(cXMLXPathContext, "register_namespaces", rxml_xpath_context_register_namespaces, 1);
|
379
|
+
rb_define_method(cXMLXPathContext, "register_namespaces_from_node", rxml_xpath_context_register_namespaces_from_node, 1);
|
380
|
+
rb_define_method(cXMLXPathContext, "register_namespace", rxml_xpath_context_register_namespace, 2);
|
381
|
+
rb_define_method(cXMLXPathContext, "node=", rxml_xpath_context_node_set, 1);
|
382
|
+
rb_define_method(cXMLXPathContext, "find", rxml_xpath_context_find, 1);
|
383
|
+
#if LIBXML_VERSION >= 20626
|
384
|
+
rb_define_method(cXMLXPathContext, "enable_cache", rxml_xpath_context_enable_cache, -1);
|
385
|
+
rb_define_method(cXMLXPathContext, "disable_cache", rxml_xpath_context_disable_cache, 0);
|
386
|
+
#endif
|
387
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/* $Id: ruby_xml_xpath_context.h 758 2009-01-25 20:36:03Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RXML_XPATH_CONTEXT__
|
6
|
+
#define __RXML_XPATH_CONTEXT__
|
7
|
+
|
8
|
+
extern VALUE cXMLXPathContext;
|
9
|
+
void rxml_init_xpath_context(void);
|
10
|
+
|
11
|
+
#endif
|
Binary file
|
@@ -0,0 +1,83 @@
|
|
1
|
+
/* $Id: rxml_xpath.c 461 2008-07-15 21:35:56Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "ruby_libxml.h"
|
6
|
+
#include "ruby_xml_xpath.h"
|
7
|
+
#include "ruby_xml_xpath_expression.h"
|
8
|
+
|
9
|
+
/*
|
10
|
+
* Document-class: LibXML::XML::XPath::Expression
|
11
|
+
*
|
12
|
+
* The XML::XPath::Expression class is used to compile
|
13
|
+
* XPath expressions so they can be parsed only once
|
14
|
+
* but reused multiple times.
|
15
|
+
*
|
16
|
+
* doc = XML::Document.string(IO.read('some xml file'))
|
17
|
+
* expr = XPath::Expression.new('//first')
|
18
|
+
* doc.root.each do |node|
|
19
|
+
* result = node.find(expr) # many, many, many times
|
20
|
+
* # ...
|
21
|
+
* end
|
22
|
+
*/
|
23
|
+
|
24
|
+
VALUE cXMLXPathExpression;
|
25
|
+
|
26
|
+
static void rxml_xpath_expression_free(xmlXPathCompExprPtr expr)
|
27
|
+
{
|
28
|
+
xmlXPathFreeCompExpr(expr);
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE rxml_xpath_expression_alloc(VALUE klass)
|
32
|
+
{
|
33
|
+
return Data_Wrap_Struct(cXMLXPathExpression, NULL,
|
34
|
+
rxml_xpath_expression_free, NULL);
|
35
|
+
}
|
36
|
+
|
37
|
+
/* call-seq:
|
38
|
+
* XPath::Expression.compile(expression) -> XPath::Expression
|
39
|
+
*
|
40
|
+
* Compiles an XPatch expression. This improves performance
|
41
|
+
* when an XPath expression is called multiple times.
|
42
|
+
*
|
43
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
44
|
+
* expr = XPath::Expression.new('//first')
|
45
|
+
* nodes = doc.find(expr)
|
46
|
+
*/
|
47
|
+
static VALUE rxml_xpath_expression_compile(VALUE klass, VALUE expression)
|
48
|
+
{
|
49
|
+
VALUE args[] = {expression};
|
50
|
+
return rb_class_new_instance(1, args, cXMLXPathExpression);
|
51
|
+
}
|
52
|
+
|
53
|
+
/* call-seq:
|
54
|
+
* XPath::Expression.new(expression) -> XPath::Expression
|
55
|
+
*
|
56
|
+
* Compiles an XPatch expression. This improves performance
|
57
|
+
* when an XPath expression is called multiple times.
|
58
|
+
*
|
59
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
60
|
+
* expr = XPath::Expression.new('//first')
|
61
|
+
* nodes = doc.find(expr)
|
62
|
+
*/
|
63
|
+
static VALUE rxml_xpath_expression_initialize(VALUE self, VALUE expression)
|
64
|
+
{
|
65
|
+
xmlXPathCompExprPtr compexpr = xmlXPathCompile((const xmlChar*)StringValueCStr(expression));
|
66
|
+
|
67
|
+
if (compexpr == NULL)
|
68
|
+
{
|
69
|
+
xmlErrorPtr xerror = xmlGetLastError();
|
70
|
+
rxml_raise(xerror);
|
71
|
+
}
|
72
|
+
|
73
|
+
DATA_PTR( self) = compexpr;
|
74
|
+
return self;
|
75
|
+
}
|
76
|
+
|
77
|
+
void rxml_init_xpath_expression(void)
|
78
|
+
{
|
79
|
+
cXMLXPathExpression = rb_define_class_under(mXPath, "Expression", rb_cObject);
|
80
|
+
rb_define_alloc_func(cXMLXPathExpression, rxml_xpath_expression_alloc);
|
81
|
+
rb_define_singleton_method(cXMLXPathExpression, "compile", rxml_xpath_expression_compile, 1);
|
82
|
+
rb_define_method(cXMLXPathExpression, "initialize", rxml_xpath_expression_initialize, 1);
|
83
|
+
}
|