libxml-ruby 0.8.3-x86-mswin32-60 → 0.9.0-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +18 -0
- data/RAKEFILE +15 -39
- data/README +48 -47
- data/ext/libxml/libxml.c +847 -22
- data/ext/libxml/ruby_libxml.h +71 -95
- data/ext/libxml/ruby_xml_attr.c +500 -500
- data/ext/libxml/ruby_xml_attributes.c +1 -1
- data/ext/libxml/ruby_xml_document.c +1144 -1135
- data/ext/libxml/ruby_xml_document.h +4 -11
- data/ext/libxml/ruby_xml_dtd.c +27 -0
- data/ext/libxml/ruby_xml_encoding.c +164 -0
- data/ext/libxml/ruby_xml_encoding.h +13 -0
- data/ext/libxml/ruby_xml_error.c +941 -0
- data/ext/libxml/ruby_xml_error.h +13 -0
- data/ext/libxml/ruby_xml_html_parser.c +71 -387
- data/ext/libxml/ruby_xml_html_parser.h +1 -17
- data/ext/libxml/ruby_xml_input.c +179 -0
- data/ext/libxml/ruby_xml_input.h +18 -0
- data/ext/libxml/ruby_xml_input_cbg.c +17 -3
- data/ext/libxml/ruby_xml_node.c +1566 -1582
- data/ext/libxml/ruby_xml_node.h +1 -4
- data/ext/libxml/ruby_xml_ns.c +14 -3
- data/ext/libxml/ruby_xml_parser.c +164 -1398
- data/ext/libxml/ruby_xml_parser.h +5 -17
- data/ext/libxml/ruby_xml_parser_context.c +131 -169
- data/ext/libxml/ruby_xml_parser_context.h +2 -9
- data/ext/libxml/ruby_xml_reader.c +910 -945
- data/ext/libxml/ruby_xml_relaxng.c +32 -3
- data/ext/libxml/ruby_xml_sax_parser.c +106 -364
- data/ext/libxml/ruby_xml_sax_parser.h +1 -37
- data/ext/libxml/ruby_xml_schema.c +174 -145
- data/ext/libxml/ruby_xml_xinclude.c +9 -5
- data/ext/libxml/ruby_xml_xpath.c +25 -6
- data/ext/libxml/ruby_xml_xpath.h +1 -2
- data/ext/libxml/ruby_xml_xpath_context.c +17 -19
- data/ext/libxml/ruby_xml_xpath_object.c +60 -56
- data/ext/libxml/ruby_xml_xpointer.c +11 -5
- data/ext/libxml/sax_parser_callbacks.inc +42 -37
- data/ext/libxml/version.h +3 -3
- data/ext/mingw/Rakefile +20 -27
- data/ext/mingw/build.rake +41 -0
- data/{lib → ext/mingw}/libiconv-2.dll +0 -0
- data/ext/mingw/libxml2-2.dll +0 -0
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.vcproj +23 -15
- data/lib/libxml.rb +8 -2
- data/lib/libxml/document.rb +16 -4
- data/lib/libxml/error.rb +84 -0
- data/lib/libxml/hpricot.rb +76 -0
- data/lib/libxml/html_parser.rb +61 -0
- data/lib/libxml/node.rb +36 -25
- data/lib/libxml/parser.rb +312 -33
- data/lib/libxml/parser_context.rb +17 -0
- data/lib/libxml/properties.rb +15 -2
- data/lib/libxml/reader.rb +15 -0
- data/lib/libxml/sax_callbacks.rb +179 -0
- data/lib/libxml/sax_parser.rb +42 -0
- data/lib/libxml/tree.rb +1 -2
- data/lib/libxml/xpath_object.rb +12 -0
- data/test/model/atom.xml +4 -0
- data/test/tc_attributes.rb +43 -19
- data/test/tc_document.rb +1 -1
- data/test/tc_document_write.rb +15 -8
- data/test/tc_dtd.rb +36 -20
- data/test/tc_encoding.rb +13 -0
- data/test/tc_error.rb +136 -0
- data/test/tc_node.rb +2 -3
- data/test/tc_node_copy.rb +1 -1
- data/test/tc_node_edit.rb +6 -0
- data/test/tc_ns.rb +18 -0
- data/test/tc_parser.rb +113 -228
- data/test/tc_parser_context.rb +1 -2
- data/test/tc_reader.rb +24 -14
- data/test/tc_relaxng.rb +18 -6
- data/test/tc_sax_parser.rb +48 -13
- data/test/tc_schema.rb +20 -8
- data/test/tc_well_formed.rb +2 -1
- data/test/tc_xml.rb +212 -0
- data/test/tc_xpath.rb +60 -46
- data/test/tc_xpointer.rb +7 -11
- data/test/test_suite.rb +4 -3
- metadata +32 -115
- data/doc/rdoc/classes/LibXML.html +0 -241
- data/doc/rdoc/classes/LibXML/XML.html +0 -185
- data/doc/rdoc/classes/LibXML/XML/Attr.html +0 -1010
- data/doc/rdoc/classes/LibXML/XML/Attributes.html +0 -526
- data/doc/rdoc/classes/LibXML/XML/Document.html +0 -1489
- data/doc/rdoc/classes/LibXML/XML/Dtd.html +0 -213
- data/doc/rdoc/classes/LibXML/XML/Error.html +0 -117
- data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +0 -348
- data/doc/rdoc/classes/LibXML/XML/InputCallbacks.html +0 -160
- data/doc/rdoc/classes/LibXML/XML/NS.html +0 -381
- data/doc/rdoc/classes/LibXML/XML/Node.html +0 -3396
- data/doc/rdoc/classes/LibXML/XML/Node/FailedModify.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Node/Set.html +0 -440
- data/doc/rdoc/classes/LibXML/XML/Node/SetNamespace.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Node/UnknownType.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Parser.html +0 -2239
- data/doc/rdoc/classes/LibXML/XML/Parser/Context.html +0 -1255
- data/doc/rdoc/classes/LibXML/XML/Parser/ParseError.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Reader.html +0 -2264
- data/doc/rdoc/classes/LibXML/XML/RelaxNG.html +0 -237
- data/doc/rdoc/classes/LibXML/XML/SaxParser.html +0 -415
- data/doc/rdoc/classes/LibXML/XML/Schema.html +0 -308
- data/doc/rdoc/classes/LibXML/XML/State.html +0 -124
- data/doc/rdoc/classes/LibXML/XML/Tree.html +0 -111
- data/doc/rdoc/classes/LibXML/XML/XInclude.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/XInclude/Error.html +0 -117
- data/doc/rdoc/classes/LibXML/XML/XMLParserOptions.html +0 -198
- data/doc/rdoc/classes/LibXML/XML/XPath.html +0 -184
- data/doc/rdoc/classes/LibXML/XML/XPath/Context.html +0 -404
- data/doc/rdoc/classes/LibXML/XML/XPath/InvalidPath.html +0 -172
- data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +0 -627
- data/doc/rdoc/classes/LibXML/XML/XPointer.html +0 -170
- data/doc/rdoc/classes/LibXML/XML/XPointer/Context.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/XPointer/Context/InvalidPath.html +0 -117
- data/doc/rdoc/classes/LibXML/XML/XPointer/InvalidExpression.html +0 -124
- data/doc/rdoc/classes/singleton.html +0 -114
- data/doc/rdoc/created.rid +0 -1
- data/doc/rdoc/files/CHANGES.html +0 -442
- data/doc/rdoc/files/LICENSE.html +0 -133
- data/doc/rdoc/files/README.html +0 -388
- data/doc/rdoc/files/VERSION.html +0 -107
- data/doc/rdoc/files/ext/libxml/cbg_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/libxml_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_set_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_ns_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_state_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_context_c.html +0 -101
- data/doc/rdoc/files/lib/libxml/attr_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/attributes_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/document_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/node_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/node_set_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/parser_options_rb.html +0 -107
- data/doc/rdoc/files/lib/libxml/parser_rb.html +0 -101
- data/doc/rdoc/files/lib/libxml/properties_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/tree_rb.html +0 -107
- data/doc/rdoc/files/lib/libxml_rb.html +0 -124
- data/doc/rdoc/files/lib/xml/libxml_rb.html +0 -124
- data/doc/rdoc/files/lib/xml_rb.html +0 -134
- data/doc/rdoc/fr_class_index.html +0 -62
- data/doc/rdoc/fr_file_index.html +0 -66
- data/doc/rdoc/fr_method_index.html +0 -392
- data/doc/rdoc/index.html +0 -24
- data/doc/rdoc/rdoc-style.css +0 -208
- data/ext/libxml/ruby_xml_node_set.c +0 -172
- data/ext/libxml/ruby_xml_node_set.h +0 -20
- data/ext/libxml/ruby_xml_xpointer_context.c +0 -22
- data/ext/libxml/ruby_xml_xpointer_context.h +0 -18
- data/lib/libxml/node_set.rb +0 -27
- data/lib/libxml2-2.dll +0 -0
- data/lib/libxml_ruby.dll.a +0 -0
- data/lib/libxml_ruby.so +0 -0
- data/test/tc_node_set.rb +0 -24
- data/test/tc_node_set2.rb +0 -37
data/ext/libxml/ruby_libxml.h
CHANGED
@@ -1,95 +1,71 @@
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
-
|
3
|
-
#ifndef __RUBY_LIBXML_H__
|
4
|
-
#define __RUBY_LIBXML_H__
|
5
|
-
|
6
|
-
#include "version.h"
|
7
|
-
|
8
|
-
#include <ruby.h>
|
9
|
-
#include <rubyio.h>
|
10
|
-
#include <util.h>
|
11
|
-
#include <libxml/parser.h>
|
12
|
-
#include <libxml/parserInternals.h>
|
13
|
-
#include <libxml/debugXML.h>
|
14
|
-
#include <libxml/xmlversion.h>
|
15
|
-
#include <libxml/xmlmemory.h>
|
16
|
-
#include <libxml/xpath.h>
|
17
|
-
#include <libxml/valid.h>
|
18
|
-
#include <libxml/catalog.h>
|
19
|
-
#include <libxml/HTMLparser.h>
|
20
|
-
#include <libxml/xmlreader.h>
|
21
|
-
|
22
|
-
// Maybe not yet defined in ruby
|
23
|
-
#ifndef RSTRING_LEN
|
24
|
-
#define RSTRING_LEN(x) RSTRING(x)->len
|
25
|
-
#endif
|
26
|
-
|
27
|
-
// not in Ruby 1.9
|
28
|
-
#ifndef GetWriteFile
|
29
|
-
#define GetWriteFile(fp) rb_io_stdio_file(fp)
|
30
|
-
#define OpenFile rb_io_t
|
31
|
-
#endif
|
32
|
-
|
33
|
-
#ifdef LIBXML_DEBUG_ENABLED
|
34
|
-
#include <libxml/xpathInternals.h>
|
35
|
-
#endif
|
36
|
-
#ifdef LIBXML_XINCLUDE_ENABLED
|
37
|
-
#include <libxml/xinclude.h>
|
38
|
-
#endif
|
39
|
-
#ifdef LIBXML_XPTR_ENABLED
|
40
|
-
#include <libxml/xpointer.h>
|
41
|
-
#endif
|
42
|
-
|
43
|
-
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#include "
|
66
|
-
#include "
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
#
|
72
|
-
#include "ruby_xml_parser.h"
|
73
|
-
#include "ruby_xml_parser_context.h"
|
74
|
-
#include "ruby_xml_sax_parser.h"
|
75
|
-
#include "ruby_xml_xinclude.h"
|
76
|
-
#include "ruby_xml_xpath.h"
|
77
|
-
#include "ruby_xml_xpath_context.h"
|
78
|
-
#include "ruby_xml_xpath_object.h"
|
79
|
-
#include "ruby_xml_xpointer.h"
|
80
|
-
#include "ruby_xml_xpointer_context.h"
|
81
|
-
#include "ruby_xml_input_cbg.h"
|
82
|
-
#include "ruby_xml_dtd.h"
|
83
|
-
#include "ruby_xml_schema.h"
|
84
|
-
#include "ruby_xml_relaxng.h"
|
85
|
-
#include "ruby_xml_html_parser.h"
|
86
|
-
#include "ruby_xml_reader.h"
|
87
|
-
|
88
|
-
extern VALUE mLibXML;
|
89
|
-
extern VALUE mXML;
|
90
|
-
extern VALUE eXMLError;
|
91
|
-
|
92
|
-
void ruby_init_parser(void);
|
93
|
-
void ruby_xml_parser_free(ruby_xml_parser *rxp);
|
94
|
-
|
95
|
-
#endif
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RUBY_LIBXML_H__
|
4
|
+
#define __RUBY_LIBXML_H__
|
5
|
+
|
6
|
+
#include "version.h"
|
7
|
+
|
8
|
+
#include <ruby.h>
|
9
|
+
#include <rubyio.h>
|
10
|
+
#include <util.h>
|
11
|
+
#include <libxml/parser.h>
|
12
|
+
#include <libxml/parserInternals.h>
|
13
|
+
#include <libxml/debugXML.h>
|
14
|
+
#include <libxml/xmlversion.h>
|
15
|
+
#include <libxml/xmlmemory.h>
|
16
|
+
#include <libxml/xpath.h>
|
17
|
+
#include <libxml/valid.h>
|
18
|
+
#include <libxml/catalog.h>
|
19
|
+
#include <libxml/HTMLparser.h>
|
20
|
+
#include <libxml/xmlreader.h>
|
21
|
+
|
22
|
+
// Maybe not yet defined in ruby
|
23
|
+
#ifndef RSTRING_LEN
|
24
|
+
#define RSTRING_LEN(x) RSTRING(x)->len
|
25
|
+
#endif
|
26
|
+
|
27
|
+
// not in Ruby 1.9
|
28
|
+
#ifndef GetWriteFile
|
29
|
+
#define GetWriteFile(fp) rb_io_stdio_file(fp)
|
30
|
+
#define OpenFile rb_io_t
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
34
|
+
#include <libxml/xpathInternals.h>
|
35
|
+
#endif
|
36
|
+
#ifdef LIBXML_XINCLUDE_ENABLED
|
37
|
+
#include <libxml/xinclude.h>
|
38
|
+
#endif
|
39
|
+
#ifdef LIBXML_XPTR_ENABLED
|
40
|
+
#include <libxml/xpointer.h>
|
41
|
+
#endif
|
42
|
+
|
43
|
+
|
44
|
+
#include "ruby_xml_encoding.h"
|
45
|
+
#include "ruby_xml_error.h"
|
46
|
+
#include "ruby_xml_input.h"
|
47
|
+
#include "ruby_xml_state.h"
|
48
|
+
#include "ruby_xml_attributes.h"
|
49
|
+
#include "ruby_xml_attr.h"
|
50
|
+
#include "ruby_xml_document.h"
|
51
|
+
#include "ruby_xml_node.h"
|
52
|
+
#include "ruby_xml_ns.h"
|
53
|
+
#include "ruby_xml_parser.h"
|
54
|
+
#include "ruby_xml_parser_context.h"
|
55
|
+
#include "ruby_xml_sax_parser.h"
|
56
|
+
#include "ruby_xml_xinclude.h"
|
57
|
+
#include "ruby_xml_xpath.h"
|
58
|
+
#include "ruby_xml_xpath_context.h"
|
59
|
+
#include "ruby_xml_xpath_object.h"
|
60
|
+
#include "ruby_xml_xpointer.h"
|
61
|
+
#include "ruby_xml_input_cbg.h"
|
62
|
+
#include "ruby_xml_dtd.h"
|
63
|
+
#include "ruby_xml_schema.h"
|
64
|
+
#include "ruby_xml_relaxng.h"
|
65
|
+
#include "ruby_xml_html_parser.h"
|
66
|
+
#include "ruby_xml_reader.h"
|
67
|
+
|
68
|
+
extern VALUE mLibXML;
|
69
|
+
extern VALUE mXML;
|
70
|
+
|
71
|
+
#endif
|
data/ext/libxml/ruby_xml_attr.c
CHANGED
@@ -1,500 +1,500 @@
|
|
1
|
-
/* $Id: ruby_xml_attr.c
|
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 single element attribute.
|
9
|
-
*
|
10
|
-
*
|
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 ruby_xml_attr_free(xmlAttrPtr xattr) {
|
27
|
-
if (!xattr) return;
|
28
|
-
|
29
|
-
if (xattr != NULL ) {
|
30
|
-
xattr->_private=NULL;
|
31
|
-
if (xattr->parent == NULL && xattr->doc == NULL ) {
|
32
|
-
#ifdef NODE_DEBUG
|
33
|
-
fprintf(stderr,"ruby_xfree rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)rxn->node,(long)rxn->node->_private);
|
34
|
-
#endif
|
35
|
-
xmlFreeProp(xattr);
|
36
|
-
}
|
37
|
-
|
38
|
-
xattr=NULL;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
void
|
43
|
-
ruby_xml_attr_mark(xmlAttrPtr xattr) {
|
44
|
-
if (xattr == NULL) return;
|
45
|
-
|
46
|
-
if (xattr->_private == NULL ) {
|
47
|
-
rb_warning("XmlAttr is not bound! (%s:%d)",
|
48
|
-
__FILE__,__LINE__);
|
49
|
-
return;
|
50
|
-
}
|
51
|
-
|
52
|
-
ruby_xml_node_mark_common((xmlNodePtr)xattr);
|
53
|
-
}
|
54
|
-
|
55
|
-
VALUE
|
56
|
-
ruby_xml_attr_wrap(xmlAttrPtr xattr)
|
57
|
-
{
|
58
|
-
VALUE result;
|
59
|
-
// This node is already wrapped
|
60
|
-
if (xattr->_private != NULL)
|
61
|
-
return (VALUE)xattr->_private;
|
62
|
-
|
63
|
-
result = Data_Wrap_Struct(cXMLAttr,
|
64
|
-
ruby_xml_attr_mark, ruby_xml_attr_free,
|
65
|
-
xattr);
|
66
|
-
|
67
|
-
xattr->_private=(void*)result;
|
68
|
-
#ifdef NODE_DEBUG
|
69
|
-
fprintf(stderr,"wrap rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)xnode,(long)obj);
|
70
|
-
#endif
|
71
|
-
return result;
|
72
|
-
}
|
73
|
-
|
74
|
-
|
75
|
-
VALUE
|
76
|
-
ruby_xml_attr_alloc(VALUE klass)
|
77
|
-
{
|
78
|
-
return Data_Wrap_Struct(cXMLAttr,
|
79
|
-
ruby_xml_attr_mark, ruby_xml_attr_free,
|
80
|
-
NULL);
|
81
|
-
}
|
82
|
-
|
83
|
-
/*
|
84
|
-
* call-seq:
|
85
|
-
* attr.initialize(node, "name", "value")
|
86
|
-
*
|
87
|
-
* Creates a new attribute for the node.
|
88
|
-
*
|
89
|
-
* node: The XML::Node that will contain the attribute
|
90
|
-
* name: The name of the attribute
|
91
|
-
* value: The value of the attribute
|
92
|
-
*
|
93
|
-
* attr = XML::Attr.new(doc.root, 'name', 'libxml')
|
94
|
-
*/
|
95
|
-
VALUE
|
96
|
-
ruby_xml_attr_initialize(int argc, VALUE *argv, VALUE self) {
|
97
|
-
VALUE node = argv[0];
|
98
|
-
VALUE name = argv[1];
|
99
|
-
VALUE value = argv[2];
|
100
|
-
VALUE ns = (argc == 4 ? argv[3] : Qnil);
|
101
|
-
|
102
|
-
xmlNodePtr xnode;
|
103
|
-
xmlAttrPtr xattr;
|
104
|
-
|
105
|
-
if ( argc < 3 || argc > 4 )
|
106
|
-
rb_raise(rb_eArgError, "
|
107
|
-
|
108
|
-
Check_Type(name, T_STRING);
|
109
|
-
Check_Type(value, T_STRING);
|
110
|
-
|
111
|
-
Data_Get_Struct(node, xmlNode, xnode);
|
112
|
-
|
113
|
-
if (xnode->type != XML_ELEMENT_NODE)
|
114
|
-
rb_raise(rb_eArgError, "Attributes can only be created on element nodes.");
|
115
|
-
|
116
|
-
if NIL_P(ns)
|
117
|
-
{
|
118
|
-
xattr = xmlNewProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
119
|
-
}
|
120
|
-
else
|
121
|
-
{
|
122
|
-
xmlNsPtr xns;
|
123
|
-
Data_Get_Struct(ns, xmlNs, xns);
|
124
|
-
xattr = xmlNewNsProp(xnode, xns, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
125
|
-
}
|
126
|
-
|
127
|
-
if (!xattr)
|
128
|
-
rb_raise(rb_eRuntimeError, "Could not create attribute.");
|
129
|
-
|
130
|
-
xattr->_private = (void *)self;
|
131
|
-
DATA_PTR(self) = xattr;
|
132
|
-
return self;
|
133
|
-
}
|
134
|
-
|
135
|
-
/*
|
136
|
-
* call-seq:
|
137
|
-
* attr.child -> node
|
138
|
-
*
|
139
|
-
* Obtain this attribute's child attribute(s).
|
140
|
-
*/
|
141
|
-
VALUE
|
142
|
-
ruby_xml_attr_child_get(VALUE self) {
|
143
|
-
xmlAttrPtr xattr;
|
144
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
145
|
-
if (xattr->children == NULL)
|
146
|
-
return(Qnil);
|
147
|
-
else
|
148
|
-
return(ruby_xml_node2_wrap(cXMLNode, (xmlNodePtr)xattr->children));
|
149
|
-
}
|
150
|
-
|
151
|
-
|
152
|
-
/*
|
153
|
-
* call-seq:
|
154
|
-
* attr.child? -> (true|false)
|
155
|
-
*
|
156
|
-
*
|
157
|
-
*/
|
158
|
-
VALUE
|
159
|
-
ruby_xml_attr_child_q(VALUE self) {
|
160
|
-
xmlAttrPtr xattr;
|
161
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
162
|
-
if (xattr->children == NULL)
|
163
|
-
return(Qfalse);
|
164
|
-
else
|
165
|
-
return(Qtrue);
|
166
|
-
}
|
167
|
-
|
168
|
-
|
169
|
-
/*
|
170
|
-
* call-seq:
|
171
|
-
* attr.doc -> XML::Document
|
172
|
-
*
|
173
|
-
* Returns this attribute's document.
|
174
|
-
*
|
175
|
-
* doc.root.attributes.get_attribute('name').doc == doc
|
176
|
-
*/
|
177
|
-
VALUE
|
178
|
-
ruby_xml_attr_doc_get(VALUE self) {
|
179
|
-
xmlAttrPtr xattr;
|
180
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
181
|
-
if (xattr->doc == NULL)
|
182
|
-
return(Qnil);
|
183
|
-
else
|
184
|
-
return(ruby_xml_document_wrap(xattr->doc));
|
185
|
-
}
|
186
|
-
|
187
|
-
/*
|
188
|
-
* call-seq:
|
189
|
-
* attr.doc? -> (true|false)
|
190
|
-
*
|
191
|
-
* Determine whether this attribute is associated with an
|
192
|
-
* XML::Document.
|
193
|
-
*/
|
194
|
-
VALUE
|
195
|
-
ruby_xml_attr_doc_q(VALUE self) {
|
196
|
-
xmlAttrPtr xattr;
|
197
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
198
|
-
if (xattr->doc == NULL)
|
199
|
-
return(Qfalse);
|
200
|
-
else
|
201
|
-
return(Qtrue);
|
202
|
-
}
|
203
|
-
|
204
|
-
|
205
|
-
/*
|
206
|
-
* call-seq:
|
207
|
-
* attr.last -> node
|
208
|
-
*
|
209
|
-
* Obtain the last attribute.
|
210
|
-
*/
|
211
|
-
VALUE
|
212
|
-
ruby_xml_attr_last_get(VALUE self) {
|
213
|
-
xmlAttrPtr xattr;
|
214
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
215
|
-
if (xattr->last == NULL)
|
216
|
-
return(Qnil);
|
217
|
-
else
|
218
|
-
return(ruby_xml_node2_wrap(cXMLNode, xattr->last));
|
219
|
-
}
|
220
|
-
|
221
|
-
|
222
|
-
/*
|
223
|
-
* call-seq:
|
224
|
-
* attr.last? -> (true|false)
|
225
|
-
*
|
226
|
-
* Determine whether this is the last attribute.
|
227
|
-
*/
|
228
|
-
VALUE
|
229
|
-
ruby_xml_attr_last_q(VALUE self) {
|
230
|
-
xmlAttrPtr xattr;
|
231
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
232
|
-
if (xattr->last == NULL)
|
233
|
-
return(Qfalse);
|
234
|
-
else
|
235
|
-
return(Qtrue);
|
236
|
-
}
|
237
|
-
|
238
|
-
/*
|
239
|
-
* call-seq:
|
240
|
-
* attr.name -> "name"
|
241
|
-
*
|
242
|
-
* Obtain this attribute's name.
|
243
|
-
*/
|
244
|
-
VALUE
|
245
|
-
ruby_xml_attr_name_get(VALUE self) {
|
246
|
-
xmlAttrPtr xattr;
|
247
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
248
|
-
|
249
|
-
if (xattr->name == NULL)
|
250
|
-
return(Qnil);
|
251
|
-
else
|
252
|
-
return(rb_str_new2((const char*)xattr->name));
|
253
|
-
}
|
254
|
-
|
255
|
-
/*
|
256
|
-
* call-seq:
|
257
|
-
* attr.next -> node
|
258
|
-
*
|
259
|
-
* Obtain the next attribute.
|
260
|
-
*/
|
261
|
-
VALUE
|
262
|
-
ruby_xml_attr_next_get(VALUE self) {
|
263
|
-
xmlAttrPtr xattr;
|
264
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
265
|
-
if (xattr->next == NULL)
|
266
|
-
return(Qnil);
|
267
|
-
else
|
268
|
-
return(ruby_xml_attr_wrap(xattr->next));
|
269
|
-
}
|
270
|
-
|
271
|
-
|
272
|
-
/*
|
273
|
-
* call-seq:
|
274
|
-
* attr.next? -> (true|false)
|
275
|
-
*
|
276
|
-
* Determine whether there is a next attribute.
|
277
|
-
*/
|
278
|
-
VALUE
|
279
|
-
ruby_xml_attr_next_q(VALUE self) {
|
280
|
-
xmlAttrPtr xattr;
|
281
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
282
|
-
if (xattr->next == NULL)
|
283
|
-
return(Qfalse);
|
284
|
-
else
|
285
|
-
return(Qtrue);
|
286
|
-
}
|
287
|
-
|
288
|
-
|
289
|
-
/*
|
290
|
-
* call-seq:
|
291
|
-
* attr.type_name -> "attribute"
|
292
|
-
*
|
293
|
-
* Obtain this attribute node's type name.
|
294
|
-
*/
|
295
|
-
VALUE
|
296
|
-
ruby_xml_attr_node_type_name(VALUE self) {
|
297
|
-
return(rb_str_new2("attribute"));
|
298
|
-
}
|
299
|
-
|
300
|
-
|
301
|
-
/*
|
302
|
-
* call-seq:
|
303
|
-
* attr.ns -> namespace
|
304
|
-
*
|
305
|
-
* Obtain this attribute's associated XML::NS, if any.
|
306
|
-
*/
|
307
|
-
VALUE
|
308
|
-
ruby_xml_attr_ns_get(VALUE self) {
|
309
|
-
xmlAttrPtr xattr;
|
310
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
311
|
-
if (xattr->ns == NULL)
|
312
|
-
return(Qnil);
|
313
|
-
else
|
314
|
-
return(ruby_xml_ns_wrap(xattr->ns));
|
315
|
-
}
|
316
|
-
|
317
|
-
|
318
|
-
/*
|
319
|
-
* call-seq:
|
320
|
-
* attr.ns? -> (true|false)
|
321
|
-
*
|
322
|
-
* Determine whether this attribute has an associated
|
323
|
-
* namespace.
|
324
|
-
*/
|
325
|
-
VALUE
|
326
|
-
ruby_xml_attr_ns_q(VALUE self) {
|
327
|
-
xmlAttrPtr xattr;
|
328
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
329
|
-
if (xattr->ns == NULL)
|
330
|
-
return(Qfalse);
|
331
|
-
else
|
332
|
-
return(Qtrue);
|
333
|
-
}
|
334
|
-
|
335
|
-
|
336
|
-
/*
|
337
|
-
* call-seq:
|
338
|
-
* attr.parent -> node
|
339
|
-
*
|
340
|
-
* Obtain this attribute node's parent.
|
341
|
-
*/
|
342
|
-
VALUE
|
343
|
-
ruby_xml_attr_parent_get(VALUE self) {
|
344
|
-
xmlAttrPtr xattr;
|
345
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
346
|
-
if (xattr->parent == NULL)
|
347
|
-
return(Qnil);
|
348
|
-
else
|
349
|
-
return(ruby_xml_node2_wrap(cXMLNode, xattr->parent));
|
350
|
-
}
|
351
|
-
|
352
|
-
|
353
|
-
/*
|
354
|
-
* call-seq:
|
355
|
-
* attr.parent? -> (true|false)
|
356
|
-
*
|
357
|
-
* Determine whether this attribute has a parent.
|
358
|
-
*/
|
359
|
-
VALUE
|
360
|
-
ruby_xml_attr_parent_q(VALUE self) {
|
361
|
-
xmlAttrPtr xattr;
|
362
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
363
|
-
if (xattr->parent == NULL)
|
364
|
-
return(Qfalse);
|
365
|
-
else
|
366
|
-
return(Qtrue);
|
367
|
-
}
|
368
|
-
|
369
|
-
|
370
|
-
/*
|
371
|
-
* call-seq:
|
372
|
-
* attr.prev -> node
|
373
|
-
*
|
374
|
-
* Obtain the previous attribute.
|
375
|
-
*/
|
376
|
-
VALUE
|
377
|
-
ruby_xml_attr_prev_get(VALUE self) {
|
378
|
-
xmlAttrPtr xattr;
|
379
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
380
|
-
if (xattr->prev == NULL)
|
381
|
-
return(Qnil);
|
382
|
-
else
|
383
|
-
return(ruby_xml_attr_wrap(xattr->prev));
|
384
|
-
}
|
385
|
-
|
386
|
-
|
387
|
-
/*
|
388
|
-
* call-seq:
|
389
|
-
* attr.prev? -> (true|false)
|
390
|
-
*
|
391
|
-
* Determine whether there is a previous attribute.
|
392
|
-
*/
|
393
|
-
VALUE
|
394
|
-
ruby_xml_attr_prev_q(VALUE self) {
|
395
|
-
xmlAttrPtr xattr;
|
396
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
397
|
-
if (xattr->prev == NULL)
|
398
|
-
return(Qfalse);
|
399
|
-
else
|
400
|
-
return(Qtrue);
|
401
|
-
}
|
402
|
-
|
403
|
-
|
404
|
-
/*
|
405
|
-
* call-seq:
|
406
|
-
* node.remove! -> nil
|
407
|
-
*
|
408
|
-
* Removes this attribute from it's parent.
|
409
|
-
*/
|
410
|
-
VALUE
|
411
|
-
ruby_xml_attr_remove_ex(VALUE self) {
|
412
|
-
xmlAttrPtr xattr;
|
413
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
414
|
-
|
415
|
-
if (xattr->_private == NULL)
|
416
|
-
xmlRemoveProp(xattr);
|
417
|
-
else
|
418
|
-
xmlUnlinkNode((xmlNodePtr)xattr);
|
419
|
-
|
420
|
-
return(Qnil);
|
421
|
-
}
|
422
|
-
|
423
|
-
/*
|
424
|
-
* call-seq:
|
425
|
-
* attr.value -> "value"
|
426
|
-
*
|
427
|
-
* Obtain the value of this attribute.
|
428
|
-
*/
|
429
|
-
VALUE
|
430
|
-
ruby_xml_attr_value_get(VALUE self) {
|
431
|
-
xmlAttrPtr xattr;
|
432
|
-
xmlChar *value;
|
433
|
-
VALUE result = Qnil;
|
434
|
-
|
435
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
436
|
-
if (ruby_xml_attr_parent_q(self) == Qtrue) {
|
437
|
-
value = xmlGetProp(xattr->parent, xattr->name);
|
438
|
-
if (value != NULL)
|
439
|
-
{
|
440
|
-
result = rb_str_new2((const char*)value);
|
441
|
-
xmlFree(value);
|
442
|
-
}
|
443
|
-
}
|
444
|
-
return(result);
|
445
|
-
}
|
446
|
-
|
447
|
-
|
448
|
-
/*
|
449
|
-
* call-seq:
|
450
|
-
* attr.value = "value"
|
451
|
-
*
|
452
|
-
* Sets the value of this attribute.
|
453
|
-
*/
|
454
|
-
VALUE
|
455
|
-
ruby_xml_attr_value_set(VALUE self, VALUE val) {
|
456
|
-
xmlAttrPtr xattr;
|
457
|
-
|
458
|
-
Check_Type(val, T_STRING);
|
459
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
460
|
-
|
461
|
-
if (xattr->ns)
|
462
|
-
xmlSetNsProp(xattr->parent, xattr->ns, xattr->name, (xmlChar*)StringValuePtr(val));
|
463
|
-
else
|
464
|
-
xmlSetProp(xattr->parent, xattr->name, (xmlChar*)StringValuePtr(val));
|
465
|
-
|
466
|
-
return(self);
|
467
|
-
}
|
468
|
-
|
469
|
-
|
470
|
-
// Rdoc needs to know
|
471
|
-
#ifdef RDOC_NEVER_DEFINED
|
472
|
-
mLibXML = rb_define_module("LibXML");
|
473
|
-
mXML = rb_define_module_under(mLibXML, "XML");
|
474
|
-
#endif
|
475
|
-
|
476
|
-
void
|
477
|
-
ruby_init_xml_attr(void) {
|
478
|
-
cXMLAttr = rb_define_class_under(mXML, "Attr", rb_cObject);
|
479
|
-
rb_define_alloc_func(cXMLAttr, ruby_xml_attr_alloc);
|
480
|
-
rb_define_method(cXMLAttr, "initialize", ruby_xml_attr_initialize, -1);
|
481
|
-
rb_define_method(cXMLAttr, "child", ruby_xml_attr_child_get, 0);
|
482
|
-
rb_define_method(cXMLAttr, "child?", ruby_xml_attr_child_q, 0);
|
483
|
-
rb_define_method(cXMLAttr, "doc", ruby_xml_attr_doc_get, 0);
|
484
|
-
rb_define_method(cXMLAttr, "doc?", ruby_xml_attr_doc_q, 0);
|
485
|
-
rb_define_method(cXMLAttr, "last", ruby_xml_attr_last_get, 0);
|
486
|
-
rb_define_method(cXMLAttr, "last?", ruby_xml_attr_last_q, 0);
|
487
|
-
rb_define_method(cXMLAttr, "name", ruby_xml_attr_name_get, 0);
|
488
|
-
rb_define_method(cXMLAttr, "next", ruby_xml_attr_next_get, 0);
|
489
|
-
rb_define_method(cXMLAttr, "next?", ruby_xml_attr_next_q, 0);
|
490
|
-
rb_define_method(cXMLAttr, "node_type_name", ruby_xml_attr_node_type_name, 0);
|
491
|
-
rb_define_method(cXMLAttr, "ns", ruby_xml_attr_ns_get, 0);
|
492
|
-
rb_define_method(cXMLAttr, "ns?", ruby_xml_attr_ns_q, 0);
|
493
|
-
rb_define_method(cXMLAttr, "parent", ruby_xml_attr_parent_get, 0);
|
494
|
-
rb_define_method(cXMLAttr, "parent?", ruby_xml_attr_parent_q, 0);
|
495
|
-
rb_define_method(cXMLAttr, "prev", ruby_xml_attr_prev_get, 0);
|
496
|
-
rb_define_method(cXMLAttr, "prev?", ruby_xml_attr_prev_q, 0);
|
497
|
-
rb_define_method(cXMLAttr, "remove!", ruby_xml_attr_remove_ex, 0);
|
498
|
-
rb_define_method(cXMLAttr, "value", ruby_xml_attr_value_get, 0);
|
499
|
-
rb_define_method(cXMLAttr, "value=", ruby_xml_attr_value_set, 1);
|
500
|
-
}
|
1
|
+
/* $Id: ruby_xml_attr.c 553 2008-11-18 02:34:38Z 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 single element attribute.
|
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 ruby_xml_attr_free(xmlAttrPtr xattr) {
|
27
|
+
if (!xattr) return;
|
28
|
+
|
29
|
+
if (xattr != NULL ) {
|
30
|
+
xattr->_private=NULL;
|
31
|
+
if (xattr->parent == NULL && xattr->doc == NULL ) {
|
32
|
+
#ifdef NODE_DEBUG
|
33
|
+
fprintf(stderr,"ruby_xfree rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)rxn->node,(long)rxn->node->_private);
|
34
|
+
#endif
|
35
|
+
xmlFreeProp(xattr);
|
36
|
+
}
|
37
|
+
|
38
|
+
xattr=NULL;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
void
|
43
|
+
ruby_xml_attr_mark(xmlAttrPtr xattr) {
|
44
|
+
if (xattr == NULL) return;
|
45
|
+
|
46
|
+
if (xattr->_private == NULL ) {
|
47
|
+
rb_warning("XmlAttr is not bound! (%s:%d)",
|
48
|
+
__FILE__,__LINE__);
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
|
52
|
+
ruby_xml_node_mark_common((xmlNodePtr)xattr);
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE
|
56
|
+
ruby_xml_attr_wrap(xmlAttrPtr xattr)
|
57
|
+
{
|
58
|
+
VALUE result;
|
59
|
+
// This node is already wrapped
|
60
|
+
if (xattr->_private != NULL)
|
61
|
+
return (VALUE)xattr->_private;
|
62
|
+
|
63
|
+
result = Data_Wrap_Struct(cXMLAttr,
|
64
|
+
ruby_xml_attr_mark, ruby_xml_attr_free,
|
65
|
+
xattr);
|
66
|
+
|
67
|
+
xattr->_private=(void*)result;
|
68
|
+
#ifdef NODE_DEBUG
|
69
|
+
fprintf(stderr,"wrap rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)xnode,(long)obj);
|
70
|
+
#endif
|
71
|
+
return result;
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
VALUE
|
76
|
+
ruby_xml_attr_alloc(VALUE klass)
|
77
|
+
{
|
78
|
+
return Data_Wrap_Struct(cXMLAttr,
|
79
|
+
ruby_xml_attr_mark, ruby_xml_attr_free,
|
80
|
+
NULL);
|
81
|
+
}
|
82
|
+
|
83
|
+
/*
|
84
|
+
* call-seq:
|
85
|
+
* attr.initialize(node, "name", "value")
|
86
|
+
*
|
87
|
+
* Creates a new attribute for the node.
|
88
|
+
*
|
89
|
+
* node: The XML::Node that will contain the attribute
|
90
|
+
* name: The name of the attribute
|
91
|
+
* value: The value of the attribute
|
92
|
+
*
|
93
|
+
* attr = XML::Attr.new(doc.root, 'name', 'libxml')
|
94
|
+
*/
|
95
|
+
VALUE
|
96
|
+
ruby_xml_attr_initialize(int argc, VALUE *argv, VALUE self) {
|
97
|
+
VALUE node = argv[0];
|
98
|
+
VALUE name = argv[1];
|
99
|
+
VALUE value = argv[2];
|
100
|
+
VALUE ns = (argc == 4 ? argv[3] : Qnil);
|
101
|
+
|
102
|
+
xmlNodePtr xnode;
|
103
|
+
xmlAttrPtr xattr;
|
104
|
+
|
105
|
+
if ( argc < 3 || argc > 4 )
|
106
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (3 or 4)");
|
107
|
+
|
108
|
+
Check_Type(name, T_STRING);
|
109
|
+
Check_Type(value, T_STRING);
|
110
|
+
|
111
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
112
|
+
|
113
|
+
if (xnode->type != XML_ELEMENT_NODE)
|
114
|
+
rb_raise(rb_eArgError, "Attributes can only be created on element nodes.");
|
115
|
+
|
116
|
+
if NIL_P(ns)
|
117
|
+
{
|
118
|
+
xattr = xmlNewProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
119
|
+
}
|
120
|
+
else
|
121
|
+
{
|
122
|
+
xmlNsPtr xns;
|
123
|
+
Data_Get_Struct(ns, xmlNs, xns);
|
124
|
+
xattr = xmlNewNsProp(xnode, xns, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
125
|
+
}
|
126
|
+
|
127
|
+
if (!xattr)
|
128
|
+
rb_raise(rb_eRuntimeError, "Could not create attribute.");
|
129
|
+
|
130
|
+
xattr->_private = (void *)self;
|
131
|
+
DATA_PTR(self) = xattr;
|
132
|
+
return self;
|
133
|
+
}
|
134
|
+
|
135
|
+
/*
|
136
|
+
* call-seq:
|
137
|
+
* attr.child -> node
|
138
|
+
*
|
139
|
+
* Obtain this attribute's child attribute(s).
|
140
|
+
*/
|
141
|
+
VALUE
|
142
|
+
ruby_xml_attr_child_get(VALUE self) {
|
143
|
+
xmlAttrPtr xattr;
|
144
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
145
|
+
if (xattr->children == NULL)
|
146
|
+
return(Qnil);
|
147
|
+
else
|
148
|
+
return(ruby_xml_node2_wrap(cXMLNode, (xmlNodePtr)xattr->children));
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
/*
|
153
|
+
* call-seq:
|
154
|
+
* attr.child? -> (true|false)
|
155
|
+
*
|
156
|
+
* Returns whether this attribute has child attributes.
|
157
|
+
*/
|
158
|
+
VALUE
|
159
|
+
ruby_xml_attr_child_q(VALUE self) {
|
160
|
+
xmlAttrPtr xattr;
|
161
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
162
|
+
if (xattr->children == NULL)
|
163
|
+
return(Qfalse);
|
164
|
+
else
|
165
|
+
return(Qtrue);
|
166
|
+
}
|
167
|
+
|
168
|
+
|
169
|
+
/*
|
170
|
+
* call-seq:
|
171
|
+
* attr.doc -> XML::Document
|
172
|
+
*
|
173
|
+
* Returns this attribute's document.
|
174
|
+
*
|
175
|
+
* doc.root.attributes.get_attribute('name').doc == doc
|
176
|
+
*/
|
177
|
+
VALUE
|
178
|
+
ruby_xml_attr_doc_get(VALUE self) {
|
179
|
+
xmlAttrPtr xattr;
|
180
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
181
|
+
if (xattr->doc == NULL)
|
182
|
+
return(Qnil);
|
183
|
+
else
|
184
|
+
return(ruby_xml_document_wrap(xattr->doc));
|
185
|
+
}
|
186
|
+
|
187
|
+
/*
|
188
|
+
* call-seq:
|
189
|
+
* attr.doc? -> (true|false)
|
190
|
+
*
|
191
|
+
* Determine whether this attribute is associated with an
|
192
|
+
* XML::Document.
|
193
|
+
*/
|
194
|
+
VALUE
|
195
|
+
ruby_xml_attr_doc_q(VALUE self) {
|
196
|
+
xmlAttrPtr xattr;
|
197
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
198
|
+
if (xattr->doc == NULL)
|
199
|
+
return(Qfalse);
|
200
|
+
else
|
201
|
+
return(Qtrue);
|
202
|
+
}
|
203
|
+
|
204
|
+
|
205
|
+
/*
|
206
|
+
* call-seq:
|
207
|
+
* attr.last -> node
|
208
|
+
*
|
209
|
+
* Obtain the last attribute.
|
210
|
+
*/
|
211
|
+
VALUE
|
212
|
+
ruby_xml_attr_last_get(VALUE self) {
|
213
|
+
xmlAttrPtr xattr;
|
214
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
215
|
+
if (xattr->last == NULL)
|
216
|
+
return(Qnil);
|
217
|
+
else
|
218
|
+
return(ruby_xml_node2_wrap(cXMLNode, xattr->last));
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
/*
|
223
|
+
* call-seq:
|
224
|
+
* attr.last? -> (true|false)
|
225
|
+
*
|
226
|
+
* Determine whether this is the last attribute.
|
227
|
+
*/
|
228
|
+
VALUE
|
229
|
+
ruby_xml_attr_last_q(VALUE self) {
|
230
|
+
xmlAttrPtr xattr;
|
231
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
232
|
+
if (xattr->last == NULL)
|
233
|
+
return(Qfalse);
|
234
|
+
else
|
235
|
+
return(Qtrue);
|
236
|
+
}
|
237
|
+
|
238
|
+
/*
|
239
|
+
* call-seq:
|
240
|
+
* attr.name -> "name"
|
241
|
+
*
|
242
|
+
* Obtain this attribute's name.
|
243
|
+
*/
|
244
|
+
VALUE
|
245
|
+
ruby_xml_attr_name_get(VALUE self) {
|
246
|
+
xmlAttrPtr xattr;
|
247
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
248
|
+
|
249
|
+
if (xattr->name == NULL)
|
250
|
+
return(Qnil);
|
251
|
+
else
|
252
|
+
return(rb_str_new2((const char*)xattr->name));
|
253
|
+
}
|
254
|
+
|
255
|
+
/*
|
256
|
+
* call-seq:
|
257
|
+
* attr.next -> node
|
258
|
+
*
|
259
|
+
* Obtain the next attribute.
|
260
|
+
*/
|
261
|
+
VALUE
|
262
|
+
ruby_xml_attr_next_get(VALUE self) {
|
263
|
+
xmlAttrPtr xattr;
|
264
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
265
|
+
if (xattr->next == NULL)
|
266
|
+
return(Qnil);
|
267
|
+
else
|
268
|
+
return(ruby_xml_attr_wrap(xattr->next));
|
269
|
+
}
|
270
|
+
|
271
|
+
|
272
|
+
/*
|
273
|
+
* call-seq:
|
274
|
+
* attr.next? -> (true|false)
|
275
|
+
*
|
276
|
+
* Determine whether there is a next attribute.
|
277
|
+
*/
|
278
|
+
VALUE
|
279
|
+
ruby_xml_attr_next_q(VALUE self) {
|
280
|
+
xmlAttrPtr xattr;
|
281
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
282
|
+
if (xattr->next == NULL)
|
283
|
+
return(Qfalse);
|
284
|
+
else
|
285
|
+
return(Qtrue);
|
286
|
+
}
|
287
|
+
|
288
|
+
|
289
|
+
/*
|
290
|
+
* call-seq:
|
291
|
+
* attr.type_name -> "attribute"
|
292
|
+
*
|
293
|
+
* Obtain this attribute node's type name.
|
294
|
+
*/
|
295
|
+
VALUE
|
296
|
+
ruby_xml_attr_node_type_name(VALUE self) {
|
297
|
+
return(rb_str_new2("attribute"));
|
298
|
+
}
|
299
|
+
|
300
|
+
|
301
|
+
/*
|
302
|
+
* call-seq:
|
303
|
+
* attr.ns -> namespace
|
304
|
+
*
|
305
|
+
* Obtain this attribute's associated XML::NS, if any.
|
306
|
+
*/
|
307
|
+
VALUE
|
308
|
+
ruby_xml_attr_ns_get(VALUE self) {
|
309
|
+
xmlAttrPtr xattr;
|
310
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
311
|
+
if (xattr->ns == NULL)
|
312
|
+
return(Qnil);
|
313
|
+
else
|
314
|
+
return(ruby_xml_ns_wrap(xattr->ns));
|
315
|
+
}
|
316
|
+
|
317
|
+
|
318
|
+
/*
|
319
|
+
* call-seq:
|
320
|
+
* attr.ns? -> (true|false)
|
321
|
+
*
|
322
|
+
* Determine whether this attribute has an associated
|
323
|
+
* namespace.
|
324
|
+
*/
|
325
|
+
VALUE
|
326
|
+
ruby_xml_attr_ns_q(VALUE self) {
|
327
|
+
xmlAttrPtr xattr;
|
328
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
329
|
+
if (xattr->ns == NULL)
|
330
|
+
return(Qfalse);
|
331
|
+
else
|
332
|
+
return(Qtrue);
|
333
|
+
}
|
334
|
+
|
335
|
+
|
336
|
+
/*
|
337
|
+
* call-seq:
|
338
|
+
* attr.parent -> node
|
339
|
+
*
|
340
|
+
* Obtain this attribute node's parent.
|
341
|
+
*/
|
342
|
+
VALUE
|
343
|
+
ruby_xml_attr_parent_get(VALUE self) {
|
344
|
+
xmlAttrPtr xattr;
|
345
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
346
|
+
if (xattr->parent == NULL)
|
347
|
+
return(Qnil);
|
348
|
+
else
|
349
|
+
return(ruby_xml_node2_wrap(cXMLNode, xattr->parent));
|
350
|
+
}
|
351
|
+
|
352
|
+
|
353
|
+
/*
|
354
|
+
* call-seq:
|
355
|
+
* attr.parent? -> (true|false)
|
356
|
+
*
|
357
|
+
* Determine whether this attribute has a parent.
|
358
|
+
*/
|
359
|
+
VALUE
|
360
|
+
ruby_xml_attr_parent_q(VALUE self) {
|
361
|
+
xmlAttrPtr xattr;
|
362
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
363
|
+
if (xattr->parent == NULL)
|
364
|
+
return(Qfalse);
|
365
|
+
else
|
366
|
+
return(Qtrue);
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
/*
|
371
|
+
* call-seq:
|
372
|
+
* attr.prev -> node
|
373
|
+
*
|
374
|
+
* Obtain the previous attribute.
|
375
|
+
*/
|
376
|
+
VALUE
|
377
|
+
ruby_xml_attr_prev_get(VALUE self) {
|
378
|
+
xmlAttrPtr xattr;
|
379
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
380
|
+
if (xattr->prev == NULL)
|
381
|
+
return(Qnil);
|
382
|
+
else
|
383
|
+
return(ruby_xml_attr_wrap(xattr->prev));
|
384
|
+
}
|
385
|
+
|
386
|
+
|
387
|
+
/*
|
388
|
+
* call-seq:
|
389
|
+
* attr.prev? -> (true|false)
|
390
|
+
*
|
391
|
+
* Determine whether there is a previous attribute.
|
392
|
+
*/
|
393
|
+
VALUE
|
394
|
+
ruby_xml_attr_prev_q(VALUE self) {
|
395
|
+
xmlAttrPtr xattr;
|
396
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
397
|
+
if (xattr->prev == NULL)
|
398
|
+
return(Qfalse);
|
399
|
+
else
|
400
|
+
return(Qtrue);
|
401
|
+
}
|
402
|
+
|
403
|
+
|
404
|
+
/*
|
405
|
+
* call-seq:
|
406
|
+
* node.remove! -> nil
|
407
|
+
*
|
408
|
+
* Removes this attribute from it's parent.
|
409
|
+
*/
|
410
|
+
VALUE
|
411
|
+
ruby_xml_attr_remove_ex(VALUE self) {
|
412
|
+
xmlAttrPtr xattr;
|
413
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
414
|
+
|
415
|
+
if (xattr->_private == NULL)
|
416
|
+
xmlRemoveProp(xattr);
|
417
|
+
else
|
418
|
+
xmlUnlinkNode((xmlNodePtr)xattr);
|
419
|
+
|
420
|
+
return(Qnil);
|
421
|
+
}
|
422
|
+
|
423
|
+
/*
|
424
|
+
* call-seq:
|
425
|
+
* attr.value -> "value"
|
426
|
+
*
|
427
|
+
* Obtain the value of this attribute.
|
428
|
+
*/
|
429
|
+
VALUE
|
430
|
+
ruby_xml_attr_value_get(VALUE self) {
|
431
|
+
xmlAttrPtr xattr;
|
432
|
+
xmlChar *value;
|
433
|
+
VALUE result = Qnil;
|
434
|
+
|
435
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
436
|
+
if (ruby_xml_attr_parent_q(self) == Qtrue) {
|
437
|
+
value = xmlGetProp(xattr->parent, xattr->name);
|
438
|
+
if (value != NULL)
|
439
|
+
{
|
440
|
+
result = rb_str_new2((const char*)value);
|
441
|
+
xmlFree(value);
|
442
|
+
}
|
443
|
+
}
|
444
|
+
return(result);
|
445
|
+
}
|
446
|
+
|
447
|
+
|
448
|
+
/*
|
449
|
+
* call-seq:
|
450
|
+
* attr.value = "value"
|
451
|
+
*
|
452
|
+
* Sets the value of this attribute.
|
453
|
+
*/
|
454
|
+
VALUE
|
455
|
+
ruby_xml_attr_value_set(VALUE self, VALUE val) {
|
456
|
+
xmlAttrPtr xattr;
|
457
|
+
|
458
|
+
Check_Type(val, T_STRING);
|
459
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
460
|
+
|
461
|
+
if (xattr->ns)
|
462
|
+
xmlSetNsProp(xattr->parent, xattr->ns, xattr->name, (xmlChar*)StringValuePtr(val));
|
463
|
+
else
|
464
|
+
xmlSetProp(xattr->parent, xattr->name, (xmlChar*)StringValuePtr(val));
|
465
|
+
|
466
|
+
return(self);
|
467
|
+
}
|
468
|
+
|
469
|
+
|
470
|
+
// Rdoc needs to know
|
471
|
+
#ifdef RDOC_NEVER_DEFINED
|
472
|
+
mLibXML = rb_define_module("LibXML");
|
473
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
474
|
+
#endif
|
475
|
+
|
476
|
+
void
|
477
|
+
ruby_init_xml_attr(void) {
|
478
|
+
cXMLAttr = rb_define_class_under(mXML, "Attr", rb_cObject);
|
479
|
+
rb_define_alloc_func(cXMLAttr, ruby_xml_attr_alloc);
|
480
|
+
rb_define_method(cXMLAttr, "initialize", ruby_xml_attr_initialize, -1);
|
481
|
+
rb_define_method(cXMLAttr, "child", ruby_xml_attr_child_get, 0);
|
482
|
+
rb_define_method(cXMLAttr, "child?", ruby_xml_attr_child_q, 0);
|
483
|
+
rb_define_method(cXMLAttr, "doc", ruby_xml_attr_doc_get, 0);
|
484
|
+
rb_define_method(cXMLAttr, "doc?", ruby_xml_attr_doc_q, 0);
|
485
|
+
rb_define_method(cXMLAttr, "last", ruby_xml_attr_last_get, 0);
|
486
|
+
rb_define_method(cXMLAttr, "last?", ruby_xml_attr_last_q, 0);
|
487
|
+
rb_define_method(cXMLAttr, "name", ruby_xml_attr_name_get, 0);
|
488
|
+
rb_define_method(cXMLAttr, "next", ruby_xml_attr_next_get, 0);
|
489
|
+
rb_define_method(cXMLAttr, "next?", ruby_xml_attr_next_q, 0);
|
490
|
+
rb_define_method(cXMLAttr, "node_type_name", ruby_xml_attr_node_type_name, 0);
|
491
|
+
rb_define_method(cXMLAttr, "ns", ruby_xml_attr_ns_get, 0);
|
492
|
+
rb_define_method(cXMLAttr, "ns?", ruby_xml_attr_ns_q, 0);
|
493
|
+
rb_define_method(cXMLAttr, "parent", ruby_xml_attr_parent_get, 0);
|
494
|
+
rb_define_method(cXMLAttr, "parent?", ruby_xml_attr_parent_q, 0);
|
495
|
+
rb_define_method(cXMLAttr, "prev", ruby_xml_attr_prev_get, 0);
|
496
|
+
rb_define_method(cXMLAttr, "prev?", ruby_xml_attr_prev_q, 0);
|
497
|
+
rb_define_method(cXMLAttr, "remove!", ruby_xml_attr_remove_ex, 0);
|
498
|
+
rb_define_method(cXMLAttr, "value", ruby_xml_attr_value_get, 0);
|
499
|
+
rb_define_method(cXMLAttr, "value=", ruby_xml_attr_value_set, 1);
|
500
|
+
}
|