libxml-ruby 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +49 -0
- data/LICENSE +22 -0
- data/README +129 -0
- data/Rakefile +197 -0
- data/TODO +84 -0
- data/ext/xml/cbg.c +76 -0
- data/ext/xml/extconf.rb +95 -0
- data/ext/xml/libxml.c +86 -0
- data/ext/xml/libxml.h +79 -0
- data/ext/xml/ruby_xml_attr.c +372 -0
- data/ext/xml/ruby_xml_attr.h +21 -0
- data/ext/xml/ruby_xml_attribute.c +224 -0
- data/ext/xml/ruby_xml_attribute.h +21 -0
- data/ext/xml/ruby_xml_document.c +1159 -0
- data/ext/xml/ruby_xml_document.h +27 -0
- data/ext/xml/ruby_xml_dtd.c +168 -0
- data/ext/xml/ruby_xml_dtd.h +17 -0
- data/ext/xml/ruby_xml_input_cbg.c +167 -0
- data/ext/xml/ruby_xml_input_cbg.h +21 -0
- data/ext/xml/ruby_xml_node.c +2052 -0
- data/ext/xml/ruby_xml_node.h +28 -0
- data/ext/xml/ruby_xml_node_set.c +197 -0
- data/ext/xml/ruby_xml_node_set.h +26 -0
- data/ext/xml/ruby_xml_ns.c +153 -0
- data/ext/xml/ruby_xml_ns.h +21 -0
- data/ext/xml/ruby_xml_parser.c +1363 -0
- data/ext/xml/ruby_xml_parser.h +31 -0
- data/ext/xml/ruby_xml_parser_context.c +715 -0
- data/ext/xml/ruby_xml_parser_context.h +22 -0
- data/ext/xml/ruby_xml_sax_parser.c +181 -0
- data/ext/xml/ruby_xml_sax_parser.h +21 -0
- data/ext/xml/ruby_xml_schema.c +142 -0
- data/ext/xml/ruby_xml_schema.h +16 -0
- data/ext/xml/ruby_xml_tree.c +43 -0
- data/ext/xml/ruby_xml_tree.h +12 -0
- data/ext/xml/ruby_xml_xinclude.c +20 -0
- data/ext/xml/ruby_xml_xinclude.h +13 -0
- data/ext/xml/ruby_xml_xpath.c +357 -0
- data/ext/xml/ruby_xml_xpath.h +24 -0
- data/ext/xml/ruby_xml_xpath_context.c +124 -0
- data/ext/xml/ruby_xml_xpath_context.h +24 -0
- data/ext/xml/ruby_xml_xpointer.c +100 -0
- data/ext/xml/ruby_xml_xpointer.h +27 -0
- data/ext/xml/ruby_xml_xpointer_context.c +22 -0
- data/ext/xml/ruby_xml_xpointer_context.h +18 -0
- data/tests/copy_bug.rb +21 -0
- data/tests/dtd-test.rb +24 -0
- data/tests/model/default_validation_bug.rb +0 -0
- data/tests/model/rubynet.xml +78 -0
- data/tests/model/rubynet_project +13 -0
- data/tests/model/xinclude.xml +5 -0
- data/tests/runner.rb +13 -0
- data/tests/schema-test.rb +74 -0
- data/tests/tc_default_validation.rb +0 -0
- data/tests/tc_xml_document.rb +51 -0
- data/tests/tc_xml_document_write.rb +25 -0
- data/tests/tc_xml_document_write2.rb +55 -0
- data/tests/tc_xml_document_write3.rb +97 -0
- data/tests/tc_xml_node.rb +59 -0
- data/tests/tc_xml_node2.rb +26 -0
- data/tests/tc_xml_node_set.rb +25 -0
- data/tests/tc_xml_node_xlink.rb +28 -0
- data/tests/tc_xml_parser.rb +175 -0
- data/tests/tc_xml_parser2.rb +17 -0
- data/tests/tc_xml_parser3.rb +23 -0
- data/tests/tc_xml_parser4.rb +33 -0
- data/tests/tc_xml_parser5.rb +27 -0
- data/tests/tc_xml_parser6.rb +23 -0
- data/tests/tc_xml_parser7.rb +28 -0
- data/tests/tc_xml_parser_context.rb +89 -0
- data/tests/tc_xml_xinclude.rb +30 -0
- data/tests/tc_xml_xpath.rb +23 -0
- data/tests/tc_xml_xpointer.rb +78 -0
- metadata +144 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
/* $Id: ruby_xml_xpath_context.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RUBY_XML_XPATH_CONTEXT__
|
6
|
+
#define __RUBY_XML_XPATH_CONTEXT__
|
7
|
+
|
8
|
+
VALUE cXMLXPathContext;
|
9
|
+
|
10
|
+
typedef struct ruby_xml_xpath_context {
|
11
|
+
VALUE xd;
|
12
|
+
xmlXPathContextPtr ctxt;
|
13
|
+
} ruby_xml_xpath_context;
|
14
|
+
|
15
|
+
void ruby_xml_xpath_context_free(ruby_xml_xpath_context *rxxpc);
|
16
|
+
VALUE ruby_xml_xpath_context_new(VALUE class, VALUE xd,
|
17
|
+
xmlXPathContextPtr ctxt);
|
18
|
+
VALUE ruby_xml_xpath_context_new2(VALUE xd, xmlXPathContextPtr ctxt);
|
19
|
+
VALUE ruby_xml_xpath_context_new3(VALUE xd);
|
20
|
+
VALUE ruby_xml_xpath_context_new4(VALUE rnode);
|
21
|
+
VALUE ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri);
|
22
|
+
void ruby_init_xml_xpath_context(void);
|
23
|
+
|
24
|
+
#endif
|
@@ -0,0 +1,100 @@
|
|
1
|
+
/* $Id: ruby_xml_xpointer.c,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "libxml.h"
|
6
|
+
#include "ruby_xml_xpointer.h"
|
7
|
+
|
8
|
+
VALUE cXMLXPointer;
|
9
|
+
VALUE eXMLXPointerInvalidExpression;
|
10
|
+
|
11
|
+
VALUE
|
12
|
+
ruby_xml_xpointer_point(VALUE class, VALUE rnode, VALUE xptr_str) {
|
13
|
+
#ifdef LIBXML_XPTR_ENABLED
|
14
|
+
ruby_xml_node *node;
|
15
|
+
ruby_xml_xpath_context *xxpc;
|
16
|
+
VALUE rxptr_xpth_ctxt, rxxp;
|
17
|
+
xmlXPathObjectPtr xpath;
|
18
|
+
|
19
|
+
Check_Type(xptr_str, T_STRING);
|
20
|
+
if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
|
21
|
+
rb_raise(rb_eTypeError, "require an XML::Node object");
|
22
|
+
|
23
|
+
Data_Get_Struct(rnode, ruby_xml_node, node);
|
24
|
+
|
25
|
+
rxptr_xpth_ctxt = ruby_xml_xpath_context_new(cXMLXPathContext, node->xd,
|
26
|
+
xmlXPtrNewContext(node->node->doc, node->node, NULL));
|
27
|
+
if (NIL_P(rxptr_xpth_ctxt))
|
28
|
+
return(Qnil);
|
29
|
+
Data_Get_Struct(rxptr_xpth_ctxt, ruby_xml_xpath_context, xxpc);
|
30
|
+
|
31
|
+
xpath = xmlXPtrEval((xmlChar*)StringValuePtr(xptr_str), xxpc->ctxt);
|
32
|
+
if (xpath == NULL)
|
33
|
+
rb_raise(eXMLXPointerInvalidExpression, "invalid xpointer expression");
|
34
|
+
|
35
|
+
rxxp = ruby_xml_xpath_new(cXMLXPath, node->xd, rxptr_xpth_ctxt, xpath);
|
36
|
+
return(rxxp);
|
37
|
+
#else
|
38
|
+
rb_warn("libxml was compiled without XPointer support");
|
39
|
+
return(Qfalse);
|
40
|
+
#endif
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
VALUE
|
45
|
+
ruby_xml_xpointer_point2(VALUE node, VALUE xptr_str) {
|
46
|
+
return(ruby_xml_xpointer_point(cXMLXPointer, node, xptr_str));
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
/*
|
51
|
+
* call-seq:
|
52
|
+
* XML::XPointer.range(start_node, end_node) => xpath
|
53
|
+
*
|
54
|
+
* Create an xpath representing the range between the supplied
|
55
|
+
* start and end node.
|
56
|
+
*/
|
57
|
+
VALUE
|
58
|
+
ruby_xml_xpointer_range(VALUE class, VALUE rstart, VALUE rend) {
|
59
|
+
#ifdef LIBXML_XPTR_ENABLED
|
60
|
+
ruby_xml_node *start, *end;
|
61
|
+
VALUE rxxp;
|
62
|
+
xmlXPathObjectPtr xpath;
|
63
|
+
|
64
|
+
if (rb_obj_is_kind_of(rstart, cXMLNode) == Qfalse)
|
65
|
+
rb_raise(rb_eTypeError, "require an XML::Node object as a starting point");
|
66
|
+
if (rb_obj_is_kind_of(rend, cXMLNode) == Qfalse)
|
67
|
+
rb_raise(rb_eTypeError, "require an XML::Node object as an ending point");
|
68
|
+
|
69
|
+
Data_Get_Struct(rstart, ruby_xml_node, start);
|
70
|
+
if (start->node == NULL)
|
71
|
+
return(Qnil);
|
72
|
+
|
73
|
+
Data_Get_Struct(rend, ruby_xml_node, end);
|
74
|
+
if (end->node == NULL)
|
75
|
+
return(Qnil);
|
76
|
+
|
77
|
+
xpath = xmlXPtrNewRangeNodes(start->node, end->node);
|
78
|
+
if (xpath == NULL)
|
79
|
+
rb_fatal("You shouldn't be able to have this happen");
|
80
|
+
|
81
|
+
rxxp = ruby_xml_xpath_new(cXMLXPath, start->xd, Qnil, xpath);
|
82
|
+
return(rxxp);
|
83
|
+
#else
|
84
|
+
rb_warn("libxml was compiled without XPointer support");
|
85
|
+
return(Qfalse);
|
86
|
+
#endif
|
87
|
+
}
|
88
|
+
|
89
|
+
// Rdoc needs to know
|
90
|
+
#ifdef RDOC_NEVER_DEFINED
|
91
|
+
mXML = rb_define_module("XML");
|
92
|
+
#endif
|
93
|
+
|
94
|
+
void
|
95
|
+
ruby_init_xml_xpointer(void) {
|
96
|
+
cXMLXPointer = rb_define_class_under(mXML, "XPointer", rb_cObject);
|
97
|
+
eXMLXPointerInvalidExpression = rb_define_class_under(cXMLXPointer, "InvalidExpression", rb_eException);
|
98
|
+
|
99
|
+
rb_define_singleton_method(cXMLXPointer, "range", ruby_xml_xpointer_range, 2);
|
100
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/* $Id: ruby_xml_xpointer.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RUBY_XML_XPOINTER__
|
6
|
+
#define __RUBY_XML_XPOINTER__
|
7
|
+
|
8
|
+
extern VALUE cXMLXPointer;
|
9
|
+
extern VALUE eXMLXPointerInvalidExpression;
|
10
|
+
|
11
|
+
typedef struct ruby_xml_xpointer {
|
12
|
+
VALUE xd;
|
13
|
+
VALUE ctxt;
|
14
|
+
/*
|
15
|
+
* This needs to go into a xpointer data struct:
|
16
|
+
*
|
17
|
+
* xmlLocationSetPtr xptr;
|
18
|
+
*
|
19
|
+
* I also need an xpointer data struct type.
|
20
|
+
*/
|
21
|
+
} ruby_xml_xpointer;
|
22
|
+
|
23
|
+
VALUE ruby_xml_xpointer_point(VALUE class, VALUE node, VALUE xptr_string);
|
24
|
+
VALUE ruby_xml_xpointer_point2(VALUE node, VALUE xptr_string);
|
25
|
+
void ruby_init_xml_xpointer(void);
|
26
|
+
|
27
|
+
#endif
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/* $Id: ruby_xml_xpointer_context.c,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "libxml.h"
|
6
|
+
#include "ruby_xml_xpointer_context.h"
|
7
|
+
|
8
|
+
VALUE cXMLXPointerContext;
|
9
|
+
VALUE eXMLXPointehContextInvalidPath;
|
10
|
+
VALUE eXMLXPointerContextInvalidPath;
|
11
|
+
|
12
|
+
// Rdoc needs to know
|
13
|
+
#ifdef RDOC_NEVER_DEFINED
|
14
|
+
mXML = rb_define_module("XML");
|
15
|
+
cXMLXPointer = rb_define_class_under(mXML, "XPointer", rb_cObject);
|
16
|
+
#endif
|
17
|
+
|
18
|
+
void
|
19
|
+
ruby_init_xml_xpointer_context(void) {
|
20
|
+
cXMLXPointerContext = rb_define_class_under(cXMLXPointer, "Context", cXMLXPathContext);
|
21
|
+
eXMLXPointerContextInvalidPath = rb_define_class_under(cXMLXPointerContext, "InvalidPath", rb_eException);
|
22
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/* $Id: ruby_xml_xpointer_context.h,v 1.1 2006/02/21 20:40:16 roscopeco Exp $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RUBY_XML_XPOINTER_CONTEXT__
|
6
|
+
#define __RUBY_XML_XPOINTER_CONTEXT__
|
7
|
+
|
8
|
+
extern VALUE cXMLXPointerContext;
|
9
|
+
extern VALUE eXMLXPointerContextInvalidPath;
|
10
|
+
|
11
|
+
typedef struct ruby_xml_xpointer_context {
|
12
|
+
VALUE xd;
|
13
|
+
xmlXPathContextPtr ctxt;
|
14
|
+
} ruby_xml_xpointer_context;
|
15
|
+
|
16
|
+
void ruby_init_xml_xpointer_context(void);
|
17
|
+
|
18
|
+
#endif
|
data/tests/copy_bug.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/ruby -w -I.
|
2
|
+
|
3
|
+
require "#{File.dirname(__FILE__)}/../ext/xml/libxml" unless defined?(XML)
|
4
|
+
|
5
|
+
def test( doc2 )
|
6
|
+
doc = XML::Document.new('1.0')
|
7
|
+
doc.root = XML::Node.new("ccc")
|
8
|
+
doc.root['aaa'] = 'aaa'
|
9
|
+
#doc.root << doc2.root # BUG!
|
10
|
+
doc.root << doc2.root.copy(true)
|
11
|
+
return doc
|
12
|
+
end
|
13
|
+
|
14
|
+
def test2
|
15
|
+
doc2 = XML::Document.new('1.0')
|
16
|
+
doc2.root = XML::Node.new("aaa")
|
17
|
+
test( doc2 )
|
18
|
+
end
|
19
|
+
|
20
|
+
1000.times { |i| puts i.to_s
|
21
|
+
test2 }
|
data/tests/dtd-test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../ext/xml/libxml" unless defined?(XML)
|
2
|
+
|
3
|
+
xp = XML::Parser.new
|
4
|
+
xp.string = '<?xml version="1.0" encoding="utf-8"?>
|
5
|
+
<root><head a="ee" id="1">ass<buzz/></head><descr>really big ass</descr></root>'
|
6
|
+
|
7
|
+
doc = xp.parse
|
8
|
+
|
9
|
+
dtd = XML::Dtd.new('
|
10
|
+
<!ELEMENT root (head, descr)>
|
11
|
+
<!ELEMENT head (#PCDATA)>
|
12
|
+
<!ATTLIST head
|
13
|
+
id NMTOKEN #REQUIRED
|
14
|
+
a CDATA #IMPLIED
|
15
|
+
>
|
16
|
+
<!ELEMENT descr (#PCDATA)>
|
17
|
+
')
|
18
|
+
|
19
|
+
if doc.validate(dtd) { |message, error| puts "#{error ? 'error' : 'warning'} : #{message}" }
|
20
|
+
puts "validation passed"
|
21
|
+
else
|
22
|
+
puts "validation failed"
|
23
|
+
end
|
24
|
+
|
File without changes
|
@@ -0,0 +1,78 @@
|
|
1
|
+
<rubynet xmlns:xlink="http://www.w3.org/1999/xlink">
|
2
|
+
<pkg version="1.0">
|
3
|
+
<meta>
|
4
|
+
<pkgname>REXML</pkgname>
|
5
|
+
<authors>
|
6
|
+
<author>
|
7
|
+
<name>Aaron Malone</name>
|
8
|
+
<email>aaron@munge.net</email>
|
9
|
+
<irc_network>irc.opentprojects.org</irc_network>
|
10
|
+
<irc_channel>#ruby-lang</irc_channel>
|
11
|
+
<irc_handle>AAmalone</irc_handle>
|
12
|
+
</author>
|
13
|
+
</authors>
|
14
|
+
<maintainers>
|
15
|
+
<maintainer>
|
16
|
+
<name>Tools Team</name>
|
17
|
+
<email>tools@gentoo.org</email>
|
18
|
+
<irc_network>irc.opentprojects.org</irc_network>
|
19
|
+
<irc_channel>#ruby-lang</irc_channel>
|
20
|
+
<irc_handle>TinyT</irc_handle>
|
21
|
+
</maintainer>
|
22
|
+
</maintainers>
|
23
|
+
<categories>
|
24
|
+
|
25
|
+
<!-- For pieces of data that are repeated constnatly, could we
|
26
|
+
use XLink to centralize some of these definitions? If we move
|
27
|
+
stuff around on rubynet.org, we don't want to have to do a
|
28
|
+
search/replace: just update the entity, IMHO. -->
|
29
|
+
|
30
|
+
<major_category xlink:type="simple" xlink:href="http://www.rubynet.org/category/xml/">XML</major_category>
|
31
|
+
<minor_category xlink:type="simple" xlink:href="http://www.rubynet.org/category/text%20processing/">Text Processing</minor_category>
|
32
|
+
<minor_category xlink:type="simple" xlink:href="http://www.rubynet.org/category/storage/">Storage</minor_category>
|
33
|
+
</categories>
|
34
|
+
<version>
|
35
|
+
<major_version>1</major_version>
|
36
|
+
<minor_version>2</minor_version>
|
37
|
+
<micro_version>3</micro_version>
|
38
|
+
</version>
|
39
|
+
<copyright>1999-2002 Gentoo Technologies,Inc.</copyright>
|
40
|
+
<license>Ruby</license>
|
41
|
+
<status>Stable</status>
|
42
|
+
<full_name>Ruby Electric XML</full_name>
|
43
|
+
<description>Pure Ruby parser, blah blah. Based of Electrice XML</description>
|
44
|
+
<homepage xlink:type="simple" xlink:href="http://www.germane-software.com/~ser/Software/rexml/">REXML Home</homepage>
|
45
|
+
<download xlink:type="simple" xlink:href="http://www.germane-software.com/~ser/Software/rexml/rexml-1.2.3.bz2/">REXML Download</download>
|
46
|
+
</meta>
|
47
|
+
<dependencies>
|
48
|
+
<dependency name="ruby" uri="http://www.rubynet.org/packages/ruby/">
|
49
|
+
<required_version restriction="no-lower-than">
|
50
|
+
<version>
|
51
|
+
<major_version>1</major_version>
|
52
|
+
<minor_version>6</minor_version>
|
53
|
+
<micro_version>0</micro_version>
|
54
|
+
</version>
|
55
|
+
</required_version>
|
56
|
+
</dependency>
|
57
|
+
</dependencies>
|
58
|
+
<files>
|
59
|
+
<file>
|
60
|
+
<filename>uga.rb</filename>
|
61
|
+
<mode>0444</mode>
|
62
|
+
<content encoding="xml">... the file here</content>
|
63
|
+
</file>
|
64
|
+
<file>
|
65
|
+
<filename>booga.h</filename>
|
66
|
+
<mode>0444</mode>
|
67
|
+
<content encoding="xml">... the file here</content>
|
68
|
+
</file>
|
69
|
+
<file>
|
70
|
+
<filename>foo.so</filename>
|
71
|
+
<mode>0555</mode>
|
72
|
+
<!-- Encode routine: str.to_a.pack('m')
|
73
|
+
Decode routine: str.unpack('m') -->
|
74
|
+
<content encoding="mime64">Li4uIHRoZSBmaWxlIGhlcmU=\n</content>
|
75
|
+
</file>
|
76
|
+
</files>
|
77
|
+
</pkg>
|
78
|
+
</rubynet>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# $Id: rubynet_project,v 1.1 2005/12/19 19:53:07 roscopeco Exp $
|
2
|
+
|
3
|
+
copyright: 2001-2003, rubynet.org
|
4
|
+
description: Ruby bindings for the libxml2 library. The API for this
|
5
|
+
module is hopefully similar to REXML, which is based on
|
6
|
+
the Electric XML library (some java lib???).
|
7
|
+
download: http://www.rubynet.org/modules/xml/libxml/
|
8
|
+
full_name: libxml
|
9
|
+
homepage: http://www.rubynet.org/modules/xml/libxml/
|
10
|
+
license: BSD style license
|
11
|
+
pkgname: libxml
|
12
|
+
rubynet_url: http://www.rubynet.org/modules/xml/libxml/
|
13
|
+
status: stable
|
data/tests/runner.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Allsuite for Eclipse and GEM.
|
4
|
+
|
5
|
+
ALL_TESTS = true
|
6
|
+
TESTS = File.expand_path(File.dirname(__FILE__))
|
7
|
+
HOME = File.expand_path(File.join(TESTS,'../ext/xml'))
|
8
|
+
|
9
|
+
#$LOAD_PATH.unshift(HOME)
|
10
|
+
require "#{HOME}/libxml"
|
11
|
+
|
12
|
+
glob = File.join(TESTS, ENV['TESTS'] || 'tc_*.rb')
|
13
|
+
Dir[glob].each { |fn| require fn }
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../ext/xml/libxml" unless defined?(XML)
|
2
|
+
|
3
|
+
xp = XML::Parser.new
|
4
|
+
xp.string = '<?xml version="1.0" encoding="utf-8"?>
|
5
|
+
|
6
|
+
<shiporder orderid="889923"
|
7
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
8
|
+
xsi:noNamespaceSchemaLocation="shiporder.xsd">
|
9
|
+
<orderperson>John Smith</orderperson>
|
10
|
+
<shipto>
|
11
|
+
<name>Ola Nordmann</name>
|
12
|
+
<address>Langgt 23</address>
|
13
|
+
<city>4000 Stavanger</city>
|
14
|
+
<country>Norway</country>
|
15
|
+
</shipto>
|
16
|
+
<item>
|
17
|
+
<title>Empire Burlesque</title>
|
18
|
+
<note>Special Edition</note>
|
19
|
+
<quantity>1</quantity>
|
20
|
+
<price>10.90</price>
|
21
|
+
</item>
|
22
|
+
<item>
|
23
|
+
<title>Hide your heart</title>
|
24
|
+
<quantity>1</quantity>
|
25
|
+
<price>9.90</price>
|
26
|
+
</item>
|
27
|
+
</shiporder>
|
28
|
+
'
|
29
|
+
|
30
|
+
doc = xp.parse
|
31
|
+
|
32
|
+
schema = XML::Schema.from_string('<?xml version="1.0" encoding="ISO-8859-1" ?>
|
33
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
34
|
+
|
35
|
+
<xs:element name="shiporder">
|
36
|
+
<xs:complexType>
|
37
|
+
<xs:sequence>
|
38
|
+
<xs:element name="orderperson" type="xs:string"/>
|
39
|
+
<xs:element name="shipto">
|
40
|
+
<xs:complexType>
|
41
|
+
<xs:sequence>
|
42
|
+
<xs:element name="name" type="xs:string"/>
|
43
|
+
<xs:element name="address" type="xs:string"/>
|
44
|
+
<xs:element name="city" type="xs:string"/>
|
45
|
+
<xs:element name="country" type="xs:string"/>
|
46
|
+
</xs:sequence>
|
47
|
+
</xs:complexType>
|
48
|
+
</xs:element>
|
49
|
+
<xs:element name="item" maxOccurs="unbounded">
|
50
|
+
<xs:complexType>
|
51
|
+
<xs:sequence>
|
52
|
+
<xs:element name="title" type="xs:string"/>
|
53
|
+
<xs:element name="note" type="xs:string" minOccurs="0"/>
|
54
|
+
<xs:element name="quantity" type="xs:positiveInteger"/>
|
55
|
+
<xs:element name="price" type="xs:decimal"/>
|
56
|
+
</xs:sequence>
|
57
|
+
</xs:complexType>
|
58
|
+
</xs:element>
|
59
|
+
</xs:sequence>
|
60
|
+
<xs:attribute name="orderid" type="xs:string" use="required"/>
|
61
|
+
</xs:complexType>
|
62
|
+
</xs:element>
|
63
|
+
|
64
|
+
</xs:schema>
|
65
|
+
')
|
66
|
+
|
67
|
+
p schema
|
68
|
+
|
69
|
+
if doc.validate_schema(schema) { |message, error| puts "#{error ? 'error' : 'warning'} : #{message}" }
|
70
|
+
puts "validation passed"
|
71
|
+
else
|
72
|
+
puts "validation failed"
|
73
|
+
end
|
74
|
+
|
File without changes
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# $Id: tc_xml_document.rb,v 1.2 2006/02/21 20:40:16 roscopeco Exp $
|
2
|
+
require 'test/unit'
|
3
|
+
require "#{File.dirname(__FILE__)}/../ext/xml/libxml" unless defined?(XML)
|
4
|
+
|
5
|
+
class TC_XML_Document < Test::Unit::TestCase
|
6
|
+
def setup()
|
7
|
+
xp = XML::Parser.new()
|
8
|
+
assert_instance_of(XML::Parser, xp)
|
9
|
+
str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
10
|
+
assert_equal(str, xp.string = str)
|
11
|
+
@doc = xp.parse
|
12
|
+
assert_instance_of(XML::Document, @doc)
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown()
|
16
|
+
@doc = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_libxml_document_find()
|
20
|
+
set = @doc.find('/ruby_array/fixnum')
|
21
|
+
assert_instance_of(XML::Node::Set, set)
|
22
|
+
xpt = set.xpath
|
23
|
+
assert_instance_of(XML::XPath, xpt)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_ruby_xml_document_compression()
|
27
|
+
if XML::Parser::enabled_zlib?
|
28
|
+
0.upto(9) do |i|
|
29
|
+
assert_equal(i, @doc.compression = i)
|
30
|
+
assert_equal(i, @doc.compression)
|
31
|
+
end
|
32
|
+
|
33
|
+
9.downto(0) do |i|
|
34
|
+
assert_equal(i, @doc.compression = i)
|
35
|
+
assert_equal(i, @doc.compression)
|
36
|
+
end
|
37
|
+
|
38
|
+
10.upto(20) do |i|
|
39
|
+
# assert_equal(9, @doc.compression = i)
|
40
|
+
assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
|
41
|
+
assert_equal(9, @doc.compression)
|
42
|
+
end
|
43
|
+
|
44
|
+
-1.downto(-10) do |i|
|
45
|
+
# assert_equal(0, @doc.compression = i)
|
46
|
+
assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
|
47
|
+
assert_equal(0, @doc.compression)
|
48
|
+
end
|
49
|
+
end # if ...enabled_zlib?
|
50
|
+
end # test_ruby_xml_document_compression()
|
51
|
+
end # TC_XML_Document
|