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
Binary file
|
@@ -0,0 +1,352 @@
|
|
1
|
+
/* $Id: ruby_xml_attr.c 847 2009-03-21 22:19:43Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
/*
|
6
|
+
* Document-class: LibXML::XML::Attr
|
7
|
+
*
|
8
|
+
* Provides access to an attribute defined on an element.
|
9
|
+
*
|
10
|
+
* Basic Usage:
|
11
|
+
*
|
12
|
+
* require 'xml'
|
13
|
+
*
|
14
|
+
* doc = XML::Document.new(<some_file>)
|
15
|
+
* attribute = doc.root.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
|
16
|
+
* attribute.name == 'href'
|
17
|
+
* attribute.value == 'http://www.mydocument.com'
|
18
|
+
* attribute.remove!
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "ruby_libxml.h"
|
22
|
+
#include "ruby_xml_attr.h"
|
23
|
+
|
24
|
+
VALUE cXMLAttr;
|
25
|
+
|
26
|
+
void rxml_attr_free(xmlAttrPtr xattr)
|
27
|
+
{
|
28
|
+
if (!xattr)
|
29
|
+
return;
|
30
|
+
|
31
|
+
xattr->_private = NULL;
|
32
|
+
|
33
|
+
if (xattr->parent == NULL && xattr->doc == NULL)
|
34
|
+
{
|
35
|
+
xmlFreeProp(xattr);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
void rxml_attr_mark(xmlAttrPtr xattr)
|
40
|
+
{
|
41
|
+
/* This can happen if Ruby does a GC run after creating the
|
42
|
+
new attribute but before initializing it. */
|
43
|
+
if (xattr == NULL)
|
44
|
+
return;
|
45
|
+
|
46
|
+
if (xattr->_private == NULL)
|
47
|
+
{
|
48
|
+
rb_warning("XmlAttr is not bound! (%s:%d)", __FILE__, __LINE__);
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
|
52
|
+
rxml_node_mark((xmlNodePtr) xattr);
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE rxml_attr_wrap(xmlAttrPtr xattr)
|
56
|
+
{
|
57
|
+
VALUE result;
|
58
|
+
|
59
|
+
/* Check if the node is already wrapped. */
|
60
|
+
if (xattr->_private != NULL)
|
61
|
+
return (VALUE) xattr->_private;
|
62
|
+
|
63
|
+
result = Data_Wrap_Struct(cXMLAttr, rxml_attr_mark, rxml_attr_free, xattr);
|
64
|
+
xattr->_private = (void*) result;
|
65
|
+
|
66
|
+
return result;
|
67
|
+
}
|
68
|
+
|
69
|
+
static VALUE rxml_attr_alloc(VALUE klass)
|
70
|
+
{
|
71
|
+
return Data_Wrap_Struct(klass, rxml_attr_mark, rxml_attr_free, NULL);
|
72
|
+
}
|
73
|
+
|
74
|
+
/*
|
75
|
+
* call-seq:
|
76
|
+
* attr.initialize(node, "name", "value")
|
77
|
+
*
|
78
|
+
* Creates a new attribute for the node.
|
79
|
+
*
|
80
|
+
* node: The XML::Node that will contain the attribute
|
81
|
+
* name: The name of the attribute
|
82
|
+
* value: The value of the attribute
|
83
|
+
*
|
84
|
+
* attr = XML::Attr.new(doc.root, 'name', 'libxml')
|
85
|
+
*/
|
86
|
+
static VALUE rxml_attr_initialize(int argc, VALUE *argv, VALUE self)
|
87
|
+
{
|
88
|
+
VALUE node = argv[0];
|
89
|
+
VALUE name = argv[1];
|
90
|
+
VALUE value = argv[2];
|
91
|
+
VALUE ns = (argc == 4 ? argv[3] : Qnil);
|
92
|
+
|
93
|
+
xmlNodePtr xnode;
|
94
|
+
xmlAttrPtr xattr;
|
95
|
+
|
96
|
+
if (argc < 3 || argc > 4)
|
97
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (3 or 4)");
|
98
|
+
|
99
|
+
Check_Type(name, T_STRING);
|
100
|
+
Check_Type(value, T_STRING);
|
101
|
+
|
102
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
103
|
+
|
104
|
+
if (xnode->type != XML_ELEMENT_NODE)
|
105
|
+
rb_raise(rb_eArgError, "Attributes can only be created on element nodes.");
|
106
|
+
|
107
|
+
if (NIL_P(ns))
|
108
|
+
{
|
109
|
+
xattr = xmlNewProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
110
|
+
}
|
111
|
+
else
|
112
|
+
{
|
113
|
+
xmlNsPtr xns;
|
114
|
+
Data_Get_Struct(ns, xmlNs, xns);
|
115
|
+
xattr = xmlNewNsProp(xnode, xns, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
116
|
+
}
|
117
|
+
|
118
|
+
if (!xattr)
|
119
|
+
rb_raise(rb_eRuntimeError, "Could not create attribute.");
|
120
|
+
|
121
|
+
xattr->_private = (void *) self;
|
122
|
+
DATA_PTR( self) = xattr;
|
123
|
+
return self;
|
124
|
+
}
|
125
|
+
|
126
|
+
/*
|
127
|
+
* call-seq:
|
128
|
+
* attr.child -> node
|
129
|
+
*
|
130
|
+
* Obtain this attribute's child attribute(s).
|
131
|
+
*/
|
132
|
+
static VALUE rxml_attr_child_get(VALUE self)
|
133
|
+
{
|
134
|
+
xmlAttrPtr xattr;
|
135
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
136
|
+
if (xattr->children == NULL)
|
137
|
+
return Qnil;
|
138
|
+
else
|
139
|
+
return rxml_node_wrap((xmlNodePtr) xattr->children);
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
/*
|
144
|
+
* call-seq:
|
145
|
+
* attr.doc -> XML::Document
|
146
|
+
*
|
147
|
+
* Returns this attribute's document.
|
148
|
+
*
|
149
|
+
* doc.root.attributes.get_attribute('name').doc == doc
|
150
|
+
*/
|
151
|
+
static VALUE rxml_attr_doc_get(VALUE self)
|
152
|
+
{
|
153
|
+
xmlAttrPtr xattr;
|
154
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
155
|
+
if (xattr->doc == NULL)
|
156
|
+
return Qnil;
|
157
|
+
else
|
158
|
+
return rxml_document_wrap(xattr->doc);
|
159
|
+
}
|
160
|
+
|
161
|
+
/*
|
162
|
+
* call-seq:
|
163
|
+
* attr.last -> node
|
164
|
+
*
|
165
|
+
* Obtain the last attribute.
|
166
|
+
*/
|
167
|
+
static VALUE rxml_attr_last_get(VALUE self)
|
168
|
+
{
|
169
|
+
xmlAttrPtr xattr;
|
170
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
171
|
+
if (xattr->last == NULL)
|
172
|
+
return Qnil;
|
173
|
+
else
|
174
|
+
return rxml_node_wrap(xattr->last);
|
175
|
+
}
|
176
|
+
|
177
|
+
/*
|
178
|
+
* call-seq:
|
179
|
+
* attr.name -> "name"
|
180
|
+
*
|
181
|
+
* Obtain this attribute's name.
|
182
|
+
*/
|
183
|
+
static VALUE rxml_attr_name_get(VALUE self)
|
184
|
+
{
|
185
|
+
xmlAttrPtr xattr;
|
186
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
187
|
+
|
188
|
+
if (xattr->name == NULL)
|
189
|
+
return Qnil;
|
190
|
+
else
|
191
|
+
return rb_str_new2((const char*) xattr->name);
|
192
|
+
}
|
193
|
+
|
194
|
+
/*
|
195
|
+
* call-seq:
|
196
|
+
* attr.next -> node
|
197
|
+
*
|
198
|
+
* Obtain the next attribute.
|
199
|
+
*/
|
200
|
+
static VALUE rxml_attr_next_get(VALUE self)
|
201
|
+
{
|
202
|
+
xmlAttrPtr xattr;
|
203
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
204
|
+
if (xattr->next == NULL)
|
205
|
+
return Qnil;
|
206
|
+
else
|
207
|
+
return rxml_attr_wrap(xattr->next);
|
208
|
+
}
|
209
|
+
|
210
|
+
/*
|
211
|
+
* call-seq:
|
212
|
+
* attr.node_type -> num
|
213
|
+
*
|
214
|
+
* Obtain this node's type identifier.
|
215
|
+
*/
|
216
|
+
static VALUE rxml_attr_node_type(VALUE self)
|
217
|
+
{
|
218
|
+
xmlAttrPtr xattr;
|
219
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
220
|
+
return INT2NUM(xattr->type);
|
221
|
+
}
|
222
|
+
|
223
|
+
/*
|
224
|
+
* call-seq:
|
225
|
+
* attr.ns -> namespace
|
226
|
+
*
|
227
|
+
* Obtain this attribute's associated XML::NS, if any.
|
228
|
+
*/
|
229
|
+
static VALUE rxml_attr_ns_get(VALUE self)
|
230
|
+
{
|
231
|
+
xmlAttrPtr xattr;
|
232
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
233
|
+
if (xattr->ns == NULL)
|
234
|
+
return Qnil;
|
235
|
+
else
|
236
|
+
return rxml_namespace_wrap(xattr->ns, NULL);
|
237
|
+
}
|
238
|
+
|
239
|
+
/*
|
240
|
+
* call-seq:
|
241
|
+
* attr.parent -> node
|
242
|
+
*
|
243
|
+
* Obtain this attribute node's parent.
|
244
|
+
*/
|
245
|
+
static VALUE rxml_attr_parent_get(VALUE self)
|
246
|
+
{
|
247
|
+
xmlAttrPtr xattr;
|
248
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
249
|
+
if (xattr->parent == NULL)
|
250
|
+
return Qnil;
|
251
|
+
else
|
252
|
+
return rxml_node_wrap(xattr->parent);
|
253
|
+
}
|
254
|
+
|
255
|
+
/*
|
256
|
+
* call-seq:
|
257
|
+
* attr.prev -> node
|
258
|
+
*
|
259
|
+
* Obtain the previous attribute.
|
260
|
+
*/
|
261
|
+
static VALUE rxml_attr_prev_get(VALUE self)
|
262
|
+
{
|
263
|
+
xmlAttrPtr xattr;
|
264
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
265
|
+
if (xattr->prev == NULL)
|
266
|
+
return Qnil;
|
267
|
+
else
|
268
|
+
return rxml_attr_wrap(xattr->prev);
|
269
|
+
}
|
270
|
+
|
271
|
+
/*
|
272
|
+
* call-seq:
|
273
|
+
* node.remove! -> nil
|
274
|
+
*
|
275
|
+
* Removes this attribute from it's parent.
|
276
|
+
*/
|
277
|
+
static VALUE rxml_attr_remove_ex(VALUE self)
|
278
|
+
{
|
279
|
+
xmlAttrPtr xattr;
|
280
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
281
|
+
|
282
|
+
if (xattr->_private == NULL)
|
283
|
+
xmlRemoveProp(xattr);
|
284
|
+
else
|
285
|
+
xmlUnlinkNode((xmlNodePtr) xattr);
|
286
|
+
|
287
|
+
return Qnil;;
|
288
|
+
}
|
289
|
+
|
290
|
+
/*
|
291
|
+
* call-seq:
|
292
|
+
* attr.value -> "value"
|
293
|
+
*
|
294
|
+
* Obtain the value of this attribute.
|
295
|
+
*/
|
296
|
+
VALUE rxml_attr_value_get(VALUE self)
|
297
|
+
{
|
298
|
+
xmlAttrPtr xattr;
|
299
|
+
xmlChar *value;
|
300
|
+
VALUE result = Qnil;
|
301
|
+
|
302
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
303
|
+
value = xmlNodeGetContent((xmlNodePtr)xattr);
|
304
|
+
|
305
|
+
if (value != NULL)
|
306
|
+
{
|
307
|
+
result = rb_str_new2((const char*) value);
|
308
|
+
xmlFree(value);
|
309
|
+
}
|
310
|
+
return result;
|
311
|
+
}
|
312
|
+
|
313
|
+
/*
|
314
|
+
* call-seq:
|
315
|
+
* attr.value = "value"
|
316
|
+
*
|
317
|
+
* Sets the value of this attribute.
|
318
|
+
*/
|
319
|
+
VALUE rxml_attr_value_set(VALUE self, VALUE val)
|
320
|
+
{
|
321
|
+
xmlAttrPtr xattr;
|
322
|
+
|
323
|
+
Check_Type(val, T_STRING);
|
324
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
325
|
+
|
326
|
+
if (xattr->ns)
|
327
|
+
xmlSetNsProp(xattr->parent, xattr->ns, xattr->name,
|
328
|
+
(xmlChar*) StringValuePtr(val));
|
329
|
+
else
|
330
|
+
xmlSetProp(xattr->parent, xattr->name, (xmlChar*) StringValuePtr(val));
|
331
|
+
|
332
|
+
return (self);
|
333
|
+
}
|
334
|
+
|
335
|
+
void rxml_init_attr(void)
|
336
|
+
{
|
337
|
+
cXMLAttr = rb_define_class_under(mXML, "Attr", rb_cObject);
|
338
|
+
rb_define_alloc_func(cXMLAttr, rxml_attr_alloc);
|
339
|
+
rb_define_method(cXMLAttr, "initialize", rxml_attr_initialize, -1);
|
340
|
+
rb_define_method(cXMLAttr, "child", rxml_attr_child_get, 0);
|
341
|
+
rb_define_method(cXMLAttr, "doc", rxml_attr_doc_get, 0);
|
342
|
+
rb_define_method(cXMLAttr, "last", rxml_attr_last_get, 0);
|
343
|
+
rb_define_method(cXMLAttr, "name", rxml_attr_name_get, 0);
|
344
|
+
rb_define_method(cXMLAttr, "next", rxml_attr_next_get, 0);
|
345
|
+
rb_define_method(cXMLAttr, "node_type", rxml_attr_node_type, 0);
|
346
|
+
rb_define_method(cXMLAttr, "ns", rxml_attr_ns_get, 0);
|
347
|
+
rb_define_method(cXMLAttr, "parent", rxml_attr_parent_get, 0);
|
348
|
+
rb_define_method(cXMLAttr, "prev", rxml_attr_prev_get, 0);
|
349
|
+
rb_define_method(cXMLAttr, "remove!", rxml_attr_remove_ex, 0);
|
350
|
+
rb_define_method(cXMLAttr, "value", rxml_attr_value_get, 0);
|
351
|
+
rb_define_method(cXMLAttr, "value=", rxml_attr_value_set, 1);
|
352
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/* $Id: ruby_xml_attr.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_ATTR__
|
6
|
+
#define __RXML_ATTR__
|
7
|
+
|
8
|
+
extern VALUE cXMLAttr;
|
9
|
+
|
10
|
+
void rxml_init_attr(void);
|
11
|
+
VALUE rxml_attr_wrap(xmlAttrPtr xattr);
|
12
|
+
VALUE rxml_attr_value_get(VALUE self);
|
13
|
+
VALUE rxml_attr_value_set(VALUE self, VALUE val);
|
14
|
+
#endif
|
Binary file
|
@@ -0,0 +1,171 @@
|
|
1
|
+
/* $Id: ruby_xml_attr.c 666 2008-12-07 00:16:50Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
/*
|
6
|
+
* Document-class: LibXML::XML::AttrDecl
|
7
|
+
*
|
8
|
+
* At attribute declaration is used in XML::Dtds to define
|
9
|
+
* what attributes are allowed on an element. An attribute
|
10
|
+
* declaration defines an attribues name, data type and default
|
11
|
+
* value (if any).
|
12
|
+
*/
|
13
|
+
|
14
|
+
#include "ruby_libxml.h"
|
15
|
+
|
16
|
+
VALUE cXMLAttrDecl;
|
17
|
+
|
18
|
+
void rxml_attr_decl_mark(xmlAttributePtr xattribute)
|
19
|
+
{
|
20
|
+
if (xattribute->_private == NULL)
|
21
|
+
{
|
22
|
+
rb_warning("AttrDecl is not bound! (%s:%d)", __FILE__, __LINE__);
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
|
26
|
+
rxml_node_mark((xmlNodePtr) xattribute);
|
27
|
+
}
|
28
|
+
|
29
|
+
VALUE rxml_attr_decl_wrap(xmlAttributePtr xattribute)
|
30
|
+
{
|
31
|
+
VALUE result;
|
32
|
+
|
33
|
+
// This node is already wrapped
|
34
|
+
if (xattribute->_private != NULL)
|
35
|
+
return (VALUE) xattribute->_private;
|
36
|
+
|
37
|
+
result = Data_Wrap_Struct(cXMLAttrDecl, rxml_attr_decl_mark, NULL, xattribute);
|
38
|
+
|
39
|
+
xattribute->_private = (void*) result;
|
40
|
+
|
41
|
+
return result;
|
42
|
+
}
|
43
|
+
|
44
|
+
/*
|
45
|
+
* call-seq:
|
46
|
+
* attr_decl.doc -> XML::Document
|
47
|
+
*
|
48
|
+
* Returns this attribute declaration's document.
|
49
|
+
*/
|
50
|
+
static VALUE rxml_attr_decl_doc_get(VALUE self)
|
51
|
+
{
|
52
|
+
xmlAttributePtr xattribute;
|
53
|
+
Data_Get_Struct(self, xmlAttribute, xattribute);
|
54
|
+
if (xattribute->doc == NULL)
|
55
|
+
return Qnil;
|
56
|
+
else
|
57
|
+
return rxml_document_wrap(xattribute->doc);
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
/*
|
62
|
+
* call-seq:
|
63
|
+
* attr_decl.name -> "name"
|
64
|
+
*
|
65
|
+
* Obtain this attribute declaration's name.
|
66
|
+
*/
|
67
|
+
static VALUE rxml_attr_decl_name_get(VALUE self)
|
68
|
+
{
|
69
|
+
xmlAttributePtr xattribute;
|
70
|
+
Data_Get_Struct(self, xmlAttribute, xattribute);
|
71
|
+
|
72
|
+
if (xattribute->name == NULL)
|
73
|
+
return Qnil;
|
74
|
+
else
|
75
|
+
return rb_str_new2((const char*) xattribute->name);
|
76
|
+
}
|
77
|
+
|
78
|
+
/*
|
79
|
+
* call-seq:
|
80
|
+
* attr_decl.next -> XML::AttrDecl
|
81
|
+
*
|
82
|
+
* Obtain the next attribute declaration.
|
83
|
+
*/
|
84
|
+
static VALUE rxml_attr_decl_next_get(VALUE self)
|
85
|
+
{
|
86
|
+
xmlAttributePtr xattribute;
|
87
|
+
Data_Get_Struct(self, xmlAttribute, xattribute);
|
88
|
+
if (xattribute->next == NULL)
|
89
|
+
return Qnil;
|
90
|
+
else
|
91
|
+
return rxml_attr_decl_wrap((xmlAttributePtr)xattribute->next);
|
92
|
+
}
|
93
|
+
|
94
|
+
/*
|
95
|
+
* call-seq:
|
96
|
+
* attr_decl.type -> num
|
97
|
+
*
|
98
|
+
* Obtain this attribute declaration's type node type.
|
99
|
+
*/
|
100
|
+
static VALUE rxml_attr_decl_node_type(VALUE self)
|
101
|
+
{
|
102
|
+
xmlAttrPtr xattr;
|
103
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
104
|
+
return INT2NUM(xattr->type);
|
105
|
+
}
|
106
|
+
|
107
|
+
/*
|
108
|
+
* call-seq:
|
109
|
+
* attr_decl.parent -> XML::Dtd
|
110
|
+
*
|
111
|
+
* Obtain this attribute declaration's parent which
|
112
|
+
* is an instance of a XML::DTD.
|
113
|
+
*/
|
114
|
+
static VALUE rxml_attr_decl_parent_get(VALUE self)
|
115
|
+
{
|
116
|
+
xmlAttributePtr xattribute;
|
117
|
+
Data_Get_Struct(self, xmlAttribute, xattribute);
|
118
|
+
|
119
|
+
if (xattribute->parent == NULL)
|
120
|
+
return Qnil;
|
121
|
+
else
|
122
|
+
return rxml_dtd_wrap(xattribute->parent);
|
123
|
+
}
|
124
|
+
|
125
|
+
/*
|
126
|
+
* call-seq:
|
127
|
+
* attr_decl.prev -> (XML::AttrDecl | XML::ElementDecl)
|
128
|
+
*
|
129
|
+
* Obtain the previous attribute declaration or the owning
|
130
|
+
* element declration (not implemented).
|
131
|
+
*/
|
132
|
+
static VALUE rxml_attr_decl_prev_get(VALUE self)
|
133
|
+
{
|
134
|
+
xmlAttributePtr xattribute;
|
135
|
+
Data_Get_Struct(self, xmlAttribute, xattribute);
|
136
|
+
|
137
|
+
if (xattribute->prev == NULL)
|
138
|
+
return Qnil;
|
139
|
+
else
|
140
|
+
return rxml_attr_decl_wrap((xmlAttributePtr)xattribute->prev);
|
141
|
+
}
|
142
|
+
|
143
|
+
/*
|
144
|
+
* call-seq:
|
145
|
+
* attr_decl.value -> "value"
|
146
|
+
*
|
147
|
+
* Obtain the default value of this attribute declaration.
|
148
|
+
*/
|
149
|
+
VALUE rxml_attr_decl_value_get(VALUE self)
|
150
|
+
{
|
151
|
+
xmlAttributePtr xattribute;
|
152
|
+
|
153
|
+
Data_Get_Struct(self, xmlAttribute, xattribute);
|
154
|
+
|
155
|
+
if (xattribute->defaultValue)
|
156
|
+
return rb_str_new2((const char *)xattribute->defaultValue);
|
157
|
+
else
|
158
|
+
return Qnil;
|
159
|
+
}
|
160
|
+
|
161
|
+
void rxml_init_attr_decl(void)
|
162
|
+
{
|
163
|
+
cXMLAttrDecl = rb_define_class_under(mXML, "AttrDecl", rb_cObject);
|
164
|
+
rb_define_method(cXMLAttrDecl, "doc", rxml_attr_decl_doc_get, 0);
|
165
|
+
rb_define_method(cXMLAttrDecl, "name", rxml_attr_decl_name_get, 0);
|
166
|
+
rb_define_method(cXMLAttrDecl, "next", rxml_attr_decl_next_get, 0);
|
167
|
+
rb_define_method(cXMLAttrDecl, "node_type", rxml_attr_decl_node_type, 0);
|
168
|
+
rb_define_method(cXMLAttrDecl, "parent", rxml_attr_decl_parent_get, 0);
|
169
|
+
rb_define_method(cXMLAttrDecl, "prev", rxml_attr_decl_prev_get, 0);
|
170
|
+
rb_define_method(cXMLAttrDecl, "value", rxml_attr_decl_value_get, 0);
|
171
|
+
}
|