xml-mapping 0.9.1 → 0.10.0
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.
- checksums.yaml +7 -0
- data/LICENSE +10 -53
- data/README.md +57 -0
- data/Rakefile +75 -85
- data/TODO.txt +12 -2
- data/examples/README +4 -4
- data/examples/cleanup.rb +11 -0
- data/examples/company_usage.intout +7 -7
- data/examples/documents_folders_usage.intout +2 -2
- data/examples/order_signature_enhanced_usage.intout +3 -3
- data/examples/order_usage.intout +26 -26
- data/examples/person.intout +3 -3
- data/examples/person_mm.intout +2 -2
- data/examples/publication.intout +2 -2
- data/examples/reader.intout +1 -1
- data/examples/stringarray_usage.intout +1 -1
- data/examples/time_augm.intout +6 -6
- data/examples/xpath_create_new.intout +13 -13
- data/examples/xpath_ensure_created.intout +2 -2
- data/examples/xpath_usage.intout +1 -1
- data/lib/xml/mapping.rb +0 -2
- data/lib/xml/mapping/base.rb +24 -9
- data/lib/xml/mapping/version.rb +1 -1
- data/test/company.rb +43 -0
- data/test/documents_folders.rb +7 -0
- data/test/multiple_mappings_test.rb +3 -1
- data/test/xml_mapping_adv_test.rb +20 -20
- data/test/xml_mapping_test.rb +31 -2
- data/{README → user_manual.md} +916 -154
- data/user_manual_xxpath.md +677 -0
- metadata +100 -112
- data/ChangeLog +0 -189
- data/README_XPATH +0 -202
- data/examples/company_usage.intin.rb +0 -19
- data/examples/documents_folders_usage.intin.rb +0 -18
- data/examples/order_signature_enhanced_usage.intin.rb +0 -12
- data/examples/order_usage.intin.rb +0 -120
- data/examples/person.intin.rb +0 -44
- data/examples/person_mm.intin.rb +0 -119
- data/examples/publication.intin.rb +0 -44
- data/examples/reader.intin.rb +0 -33
- data/examples/stringarray_usage.intin.rb +0 -11
- data/examples/time_augm.intin.rb +0 -19
- data/examples/time_augm_loading.intin.rb +0 -44
- data/examples/time_node.intin.rb +0 -79
- data/examples/time_node_w_marshallers.intin.rb +0 -48
- data/examples/xpath_create_new.intin.rb +0 -85
- data/examples/xpath_docvsroot.intin.rb +0 -30
- data/examples/xpath_ensure_created.intin.rb +0 -62
- data/examples/xpath_pathological.intin.rb +0 -42
- data/examples/xpath_usage.intin.rb +0 -51
- data/install.rb +0 -41
- data/test/xxpath_benchmark.result1.txt +0 -17
metadata
CHANGED
@@ -1,148 +1,136 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml-mapping
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Olaf Klischat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
date: 2014-09-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: An easy to use, extensible library for semi-automatically mapping Ruby
|
28
|
+
objects to XML and back. Includes an XPath interpreter.
|
29
|
+
email: olaf.klischat@gmail.com
|
18
30
|
executables: []
|
19
|
-
|
20
31
|
extensions: []
|
21
|
-
|
22
|
-
|
23
|
-
- README
|
24
|
-
-
|
25
|
-
- ChangeLog
|
32
|
+
extra_rdoc_files:
|
33
|
+
- user_manual.md
|
34
|
+
- README.md
|
35
|
+
- user_manual_xxpath.md
|
26
36
|
- TODO.txt
|
27
37
|
- doc/xpath_impl_notes.txt
|
28
|
-
files:
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
38
|
+
files:
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
32
42
|
- TODO.txt
|
33
43
|
- doc/xpath_impl_notes.txt
|
34
|
-
- lib/xml/xxpath.rb
|
35
|
-
- lib/xml/xxpath_methods.rb
|
36
|
-
- lib/xml/xxpath/steps.rb
|
37
|
-
- lib/xml/mapping/standard_nodes.rb
|
38
|
-
- lib/xml/mapping/core_classes_mapping.rb
|
39
|
-
- lib/xml/mapping/version.rb
|
40
|
-
- lib/xml/mapping/base.rb
|
41
|
-
- lib/xml/rexml_ext.rb
|
42
|
-
- lib/xml/mapping.rb
|
43
|
-
- examples/xpath_create_new.intin.rb
|
44
|
-
- examples/xpath_ensure_created.intout
|
45
|
-
- examples/time_augm_loading.intout
|
46
|
-
- examples/time_node_w_marshallers.intin.rb
|
47
|
-
- examples/order.rb
|
48
44
|
- examples/README
|
49
|
-
- examples/
|
50
|
-
- examples/
|
51
|
-
- examples/xpath_ensure_created.intin.rb
|
52
|
-
- examples/time_augm.intout
|
53
|
-
- examples/person_mm.intout
|
54
|
-
- examples/person_mm.intin.rb
|
55
|
-
- examples/order_signature_enhanced.rb
|
45
|
+
- examples/cleanup.rb
|
46
|
+
- examples/company.rb
|
56
47
|
- examples/company.xml
|
57
|
-
- examples/
|
58
|
-
- examples/
|
48
|
+
- examples/company_usage.intout
|
49
|
+
- examples/documents_folders.rb
|
50
|
+
- examples/documents_folders.xml
|
59
51
|
- examples/documents_folders_usage.intout
|
60
|
-
- examples/
|
61
|
-
- examples/
|
62
|
-
- examples/
|
63
|
-
- examples/reader.intin.rb
|
64
|
-
- examples/company_usage.intin.rb
|
65
|
-
- examples/xpath_pathological.intin.rb
|
66
|
-
- examples/xpath_pathological.intout
|
52
|
+
- examples/order.rb
|
53
|
+
- examples/order.xml
|
54
|
+
- examples/order_signature_enhanced.rb
|
67
55
|
- examples/order_signature_enhanced.xml
|
68
|
-
- examples/time_augm_loading.intin.rb
|
69
|
-
- examples/xpath_usage.intin.rb
|
70
|
-
- examples/xpath_docvsroot.intin.rb
|
71
|
-
- examples/stringarray.rb
|
72
|
-
- examples/time_node.intin.rb
|
73
|
-
- examples/publication.intin.rb
|
74
|
-
- examples/documents_folders_usage.intin.rb
|
75
|
-
- examples/xpath_usage.intout
|
76
|
-
- examples/order_signature_enhanced_usage.intin.rb
|
77
|
-
- examples/documents_folders.xml
|
78
|
-
- examples/order_usage.intin.rb
|
79
|
-
- examples/xpath_create_new.intout
|
80
|
-
- examples/company.rb
|
81
56
|
- examples/order_signature_enhanced_usage.intout
|
82
|
-
- examples/order.xml
|
83
57
|
- examples/order_usage.intout
|
58
|
+
- examples/person.intout
|
59
|
+
- examples/person_mm.intout
|
84
60
|
- examples/publication.intout
|
85
|
-
- examples/company_usage.intout
|
86
|
-
- examples/time_node_w_marshallers.intout
|
87
61
|
- examples/reader.intout
|
62
|
+
- examples/stringarray.rb
|
88
63
|
- examples/stringarray.xml
|
64
|
+
- examples/stringarray_usage.intout
|
65
|
+
- examples/time_augm.intout
|
66
|
+
- examples/time_augm_loading.intout
|
67
|
+
- examples/time_node.rb
|
68
|
+
- examples/time_node_w_marshallers.intout
|
69
|
+
- examples/time_node_w_marshallers.xml
|
70
|
+
- examples/xpath_create_new.intout
|
89
71
|
- examples/xpath_docvsroot.intout
|
90
|
-
- examples/
|
91
|
-
-
|
92
|
-
-
|
72
|
+
- examples/xpath_ensure_created.intout
|
73
|
+
- examples/xpath_pathological.intout
|
74
|
+
- examples/xpath_usage.intout
|
75
|
+
- lib/xml/mapping.rb
|
76
|
+
- lib/xml/mapping/base.rb
|
77
|
+
- lib/xml/mapping/core_classes_mapping.rb
|
78
|
+
- lib/xml/mapping/standard_nodes.rb
|
79
|
+
- lib/xml/mapping/version.rb
|
80
|
+
- lib/xml/rexml_ext.rb
|
81
|
+
- lib/xml/xxpath.rb
|
82
|
+
- lib/xml/xxpath/steps.rb
|
83
|
+
- lib/xml/xxpath_methods.rb
|
84
|
+
- test/all_tests.rb
|
85
|
+
- test/benchmark_fixtures.rb
|
86
|
+
- test/bookmarks.rb
|
87
|
+
- test/company.rb
|
88
|
+
- test/documents_folders.rb
|
93
89
|
- test/examples_test.rb
|
94
|
-
- test/fixtures/triangle_m2.xml
|
95
|
-
- test/fixtures/company1.xml
|
96
|
-
- test/fixtures/bookmarks1.xml
|
97
90
|
- test/fixtures/benchmark.xml
|
98
|
-
- test/fixtures/
|
99
|
-
- test/fixtures/
|
91
|
+
- test/fixtures/bookmarks1.xml
|
92
|
+
- test/fixtures/company1.xml
|
100
93
|
- test/fixtures/documents_folders.xml
|
101
|
-
- test/
|
102
|
-
- test/
|
103
|
-
- test/
|
104
|
-
- test/xxpath_benchmark.result1.txt
|
105
|
-
- test/tests_init.rb
|
106
|
-
- test/rexml_xpath_benchmark.rb
|
107
|
-
- test/all_tests.rb
|
108
|
-
- test/multiple_mappings_test.rb
|
94
|
+
- test/fixtures/documents_folders2.xml
|
95
|
+
- test/fixtures/triangle_m1.xml
|
96
|
+
- test/fixtures/triangle_m2.xml
|
109
97
|
- test/inheritance_test.rb
|
110
|
-
- test/
|
98
|
+
- test/multiple_mappings_test.rb
|
99
|
+
- test/rexml_xpath_benchmark.rb
|
100
|
+
- test/tests_init.rb
|
101
|
+
- test/triangle_mm.rb
|
111
102
|
- test/xml_mapping_adv_test.rb
|
112
|
-
- test/
|
113
|
-
- test/
|
114
|
-
- test/
|
115
|
-
-
|
116
|
-
-
|
117
|
-
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
103
|
+
- test/xml_mapping_test.rb
|
104
|
+
- test/xpath_test.rb
|
105
|
+
- test/xxpath_benchmark.rb
|
106
|
+
- test/xxpath_methods_test.rb
|
107
|
+
- user_manual.md
|
108
|
+
- user_manual_xxpath.md
|
109
|
+
homepage: https://github.com/multi-io/xml-mapping
|
110
|
+
licenses:
|
111
|
+
- Apache-2.0
|
112
|
+
metadata: {}
|
122
113
|
post_install_message:
|
123
|
-
rdoc_options:
|
124
|
-
- --include
|
114
|
+
rdoc_options:
|
115
|
+
- "--include"
|
125
116
|
- examples
|
126
|
-
require_paths:
|
117
|
+
require_paths:
|
127
118
|
- lib
|
128
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
-
requirements:
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
130
121
|
- - ">="
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
version:
|
133
|
-
|
134
|
-
|
135
|
-
requirements:
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
136
126
|
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version:
|
139
|
-
version:
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
140
129
|
requirements: []
|
141
|
-
|
142
130
|
rubyforge_project: xml-mapping
|
143
|
-
rubygems_version:
|
131
|
+
rubygems_version: 2.2.2
|
144
132
|
signing_key:
|
145
|
-
specification_version:
|
146
|
-
summary:
|
147
|
-
test_files:
|
133
|
+
specification_version: 4
|
134
|
+
summary: XML-Object mapper for Ruby
|
135
|
+
test_files:
|
148
136
|
- test/all_tests.rb
|
data/ChangeLog
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
2006/12/26 Olaf Klischat
|
2
|
-
|
3
|
-
* when creating a new instance of a mapping class from an XML
|
4
|
-
input, call new if possible rather than allocate (patch by Fred
|
5
|
-
Loney)
|
6
|
-
|
7
|
-
2006/04/30 Olaf Klischat
|
8
|
-
|
9
|
-
* xml/xxpath: text() steps
|
10
|
-
|
11
|
-
2006/03/31 Olaf Klischat
|
12
|
-
|
13
|
-
* SubObjectBaseNode: store marshaller/unmarshaller in
|
14
|
-
@marshaller/@unmarshaller (general policy for node
|
15
|
-
implementations is to set @options to
|
16
|
-
originally supplied option arguments and never change it; then
|
17
|
-
store "extracted" information in additional @attributes)
|
18
|
-
|
19
|
-
2006/02/19 Olaf Klischat
|
20
|
-
|
21
|
-
* xml/xxpath: child::*[@attrname='attrvalue'] steps
|
22
|
-
|
23
|
-
2006/02/19 Olaf Klischat
|
24
|
-
|
25
|
-
* xml/xxpath: .[@attrname='attrvalue'] steps
|
26
|
-
|
27
|
-
2005/12/30 Olaf Klischat
|
28
|
-
|
29
|
-
* node initializers in node's initialize() method; initialize_impl
|
30
|
-
deprecated (but retained for backward compatibility)
|
31
|
-
|
32
|
-
2005/12/28 Olaf Klischat
|
33
|
-
|
34
|
-
* :reader/:writer options to node factory functions (for partially
|
35
|
-
or completely overriding the node's functionality)
|
36
|
-
|
37
|
-
2005/12/07 Olaf Klischat
|
38
|
-
|
39
|
-
* ChangeLog file
|
40
|
-
|
41
|
-
2005/11/30 Olaf Klischat
|
42
|
-
|
43
|
-
* bugfix: clone default values to avoid external modifications
|
44
|
-
|
45
|
-
2005/11/27 Olaf Klischat
|
46
|
-
|
47
|
-
* xml/xxpath: name1|name2|... steps
|
48
|
-
|
49
|
-
2005/11/19 Olaf Klischat
|
50
|
-
|
51
|
-
* support for String and numeric types in :class attributes
|
52
|
-
|
53
|
-
2005/11/16 Olaf Klischat
|
54
|
-
|
55
|
-
* choice_node
|
56
|
-
|
57
|
-
2005/11/05 Olaf Klischat
|
58
|
-
|
59
|
-
* xml/xxpath: descendants ("//") axis
|
60
|
-
|
61
|
-
2005/10/11 Olaf Klischat
|
62
|
-
|
63
|
-
* support for "." paths/path elements (map sub-objects to XML data
|
64
|
-
from the parent object's XML element)
|
65
|
-
|
66
|
-
2005/10/05 Olaf Klischat
|
67
|
-
|
68
|
-
* multiple distinct mappings per mapping class
|
69
|
-
|
70
|
-
2005/09/30 Olaf Klischat
|
71
|
-
|
72
|
-
* @options moved from SingleAttributeNode to Node
|
73
|
-
|
74
|
-
2005/07/07 Olaf Klischat
|
75
|
-
|
76
|
-
* release 0.8
|
77
|
-
|
78
|
-
2005/07/04 Olaf Klischat
|
79
|
-
|
80
|
-
* xml/xpath / XML::XPath -> xml/xxpath / XML::XXPath, license ->
|
81
|
-
Ruby's
|
82
|
-
|
83
|
-
2005/06/29 Olaf Klischat
|
84
|
-
|
85
|
-
* when creating elt[@attr='value'] path elements, add a new
|
86
|
-
element if one with @attr='value' already existed
|
87
|
-
|
88
|
-
2005/03/30 Olaf Klischat
|
89
|
-
|
90
|
-
* add_accessor: check for existing accessors.
|
91
|
-
|
92
|
-
2005/03/05 Olaf Klischat
|
93
|
-
|
94
|
-
* better support for inheritance among mapping
|
95
|
-
classes
|
96
|
-
|
97
|
-
2005/03/03 Olaf Klischat
|
98
|
-
|
99
|
-
* "polymorphic" nodes via root element
|
100
|
-
name. SubObjectBaseNode-based nodes es use node polymorphy when
|
101
|
-
no explicit node marshaller/unmarshaller has been sp ecified.
|
102
|
-
|
103
|
-
2005/02/28 Olaf Klischat
|
104
|
-
|
105
|
-
* mapping root elt name => mapping class;
|
106
|
-
XML::Mapping::load_object_from_* implemented
|
107
|
-
|
108
|
-
2005/02/13 Olaf Klischat
|
109
|
-
|
110
|
-
* IntNode renamed & generalized to NumericNode
|
111
|
-
|
112
|
-
2005/02/12 Olaf Klischat
|
113
|
-
|
114
|
-
* renaming *_rexml => *_xml
|
115
|
-
|
116
|
-
2005/01/27 Olaf Klischat
|
117
|
-
|
118
|
-
* special exception NoAttrValueSet for indicating absence of a
|
119
|
-
specific attribute in an XML source
|
120
|
-
|
121
|
-
2005/01/23 Olaf Klischat
|
122
|
-
|
123
|
-
* some more documentation, Node.obj_initializing, setting node
|
124
|
-
values to defaults on initialization
|
125
|
-
|
126
|
-
2005/01/10 Olaf Klischat
|
127
|
-
|
128
|
-
* root_element_name
|
129
|
-
|
130
|
-
2005/01/07 Olaf Klischat
|
131
|
-
|
132
|
-
* refactoring:
|
133
|
-
|
134
|
-
Made node types (classes) dynamically addable via
|
135
|
-
XML::Mapping.add_node_class, xml/mapping.rb moved to
|
136
|
-
xml/mapping/base.rb, node types moved to
|
137
|
-
xml/mapping/standard_nodes.rb, xml/mapping.rb now requires base
|
138
|
-
and standard_nodes and adds all standard node types to
|
139
|
-
XML::Mapping.
|
140
|
-
|
141
|
-
* additional node class SingleAttributeNode < Node for nodes that
|
142
|
-
map to a single attribute in their class (that's true for all
|
143
|
-
nodes we have so far). Call to add_attribute moved from "core"
|
144
|
-
to SingleAttributeNode.initialize.
|
145
|
-
|
146
|
-
* XML::Mapping: @nodes renamed to @xml_mapping_nodes to minimize
|
147
|
-
chance of name clashes.
|
148
|
-
|
149
|
-
2004/12/30 Olaf Klischat
|
150
|
-
|
151
|
-
* array node writing, hash node writing
|
152
|
-
|
153
|
-
|
154
|
-
2004/12/30 Olaf Klischat
|
155
|
-
|
156
|
-
* xpath: create_new flag, + convenience method
|
157
|
-
|
158
|
-
2004/12/21 Olaf Klischat
|
159
|
-
|
160
|
-
* node classes
|
161
|
-
|
162
|
-
2004/12/20 Olaf Klischat
|
163
|
-
|
164
|
-
* hash_node
|
165
|
-
|
166
|
-
2004/12/08 Olaf Klischat
|
167
|
-
|
168
|
-
* xpath: attribute nodes
|
169
|
-
|
170
|
-
* xml_mapping: retargeted from REXML::XPath to XML::XPath
|
171
|
-
|
172
|
-
2004/12/02 Olaf Klischat
|
173
|
-
|
174
|
-
* xpath: write accessors
|
175
|
-
|
176
|
-
2004/11/27 Olaf Klischat
|
177
|
-
|
178
|
-
* xpath: read access seems to work
|
179
|
-
|
180
|
-
2004/11/25 Olaf Klischat
|
181
|
-
|
182
|
-
* array_node
|
183
|
-
|
184
|
-
stone age Olaf Klischat
|
185
|
-
|
186
|
-
* see http://rubygarden.org/ruby?XmlMapping
|
187
|
-
|
188
|
-
|
189
|
-
|
data/README_XPATH
DELETED
@@ -1,202 +0,0 @@
|
|
1
|
-
= XML-XXPATH
|
2
|
-
|
3
|
-
== Overview, Motivation
|
4
|
-
|
5
|
-
Xml-xxpath is an (incomplete) XPath interpreter that is at the moment
|
6
|
-
bundled with xml-mapping. It is built on top of REXML. xml-mapping
|
7
|
-
uses xml-xxpath extensively for implementing its node types -- see the
|
8
|
-
README file and the reference documentation (and the source code) for
|
9
|
-
details. xml-xxpath, however, does not depend on xml-mapping at all,
|
10
|
-
and is useful in its own right -- maybe I'll later distribute it as a
|
11
|
-
seperate library instead of bundling it. For the time being, if you
|
12
|
-
want to use this XPath implementation stand-alone, you can just rip
|
13
|
-
the files <tt>lib/xml/xxpath.rb</tt>,
|
14
|
-
<tt>lib/xml/xxpath/steps.rb</tt>, and
|
15
|
-
<tt>lib/xml/xxpath_methods.rb</tt> out of the xml-mapping distribution
|
16
|
-
and use them on their own (they do not depend on anything else).
|
17
|
-
|
18
|
-
xml-xxpath's XPath support is vastly incomplete (see below), but, in
|
19
|
-
addition to the normal reading/matching functionality found in other
|
20
|
-
XPath implementations (i.e. "find all elements in a given XML document
|
21
|
-
matching a given XPath expression"), xml-xxpath supports <i>write
|
22
|
-
access</i>. For example, when writing the XPath expression
|
23
|
-
"/foo/bar[3]/baz[@key='hiho']" to the XML document
|
24
|
-
|
25
|
-
<foo>
|
26
|
-
<bar>
|
27
|
-
<baz key='ab'>hello</baz>
|
28
|
-
<baz key='xy'>goodbye</baz>
|
29
|
-
</bar>
|
30
|
-
</foo>
|
31
|
-
|
32
|
-
, you'll get:
|
33
|
-
|
34
|
-
<foo>
|
35
|
-
<bar>
|
36
|
-
<baz key='ab'>hello</baz>
|
37
|
-
<baz key='xy'>goodbye</baz>
|
38
|
-
</bar>
|
39
|
-
<bar/>
|
40
|
-
<bar><baz key='hiho'/></bar>
|
41
|
-
</foo>
|
42
|
-
|
43
|
-
This feature is used by xml-mapping when writing (marshalling) Ruby
|
44
|
-
objects to XML, and is actually the reason why I couldn't just use any
|
45
|
-
of the existing XPath implementations, e.g. the one that comes with
|
46
|
-
REXML. Also, the whole xml-xxpath implementation is just 300 lines of
|
47
|
-
Ruby code, it is quite fast (paths are precompiled), and xml-xxpath
|
48
|
-
returns matched elements in the order they appeared in the source
|
49
|
-
document -- I've heard REXML::XPath doesn't do that :)
|
50
|
-
|
51
|
-
Some basic knowledge of XPath is helpful for reading this document.
|
52
|
-
|
53
|
-
At the moment, xml-xxpath understands XPath expressions of the form
|
54
|
-
[<tt>/</tt>]_pathelement_<tt>/[/]</tt>_pathelement_<tt>/[/]</tt>...,
|
55
|
-
where each _pathelement_ must be one of these:
|
56
|
-
|
57
|
-
- a simple element name _name_, e.g. +signature+
|
58
|
-
|
59
|
-
- an attribute name, @_attr_name_, e.g. <tt>@key</tt>
|
60
|
-
|
61
|
-
- a combination of an element name and an attribute name and
|
62
|
-
-value, in the form _elt_name_[@_attr_name_='_attr_value_']
|
63
|
-
|
64
|
-
- an element name and an index, _elt_name_[_index_]
|
65
|
-
|
66
|
-
- the "match-all" path element, <tt>*</tt>
|
67
|
-
|
68
|
-
- .
|
69
|
-
|
70
|
-
- name1|name2|...
|
71
|
-
|
72
|
-
- .[@key='xy'] / self::*[@key='xy']
|
73
|
-
|
74
|
-
- child::*[@key='xy']
|
75
|
-
|
76
|
-
- text()
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
Xml-xxpath only supports relative paths at this time, i.e. XPath
|
81
|
-
expressions beginning with "/" or "//" will still only find nodes
|
82
|
-
below the node the expression is applied to (as if you had written
|
83
|
-
"./" or ".//", respectively).
|
84
|
-
|
85
|
-
|
86
|
-
== Usage
|
87
|
-
|
88
|
-
Xml-xxpath defines the class XML::XXPath. An instance of that class
|
89
|
-
wraps an XPath expression, the string representation of which must be
|
90
|
-
supplied when constructing the instance. You then call instance
|
91
|
-
methods like _first_, _all_ or <i>create_new</i> on the instance,
|
92
|
-
supplying the REXML Element the XPath expression should be applied to,
|
93
|
-
and get the results, or, in the case of write access, the element is
|
94
|
-
updated in-place.
|
95
|
-
|
96
|
-
|
97
|
-
=== Read Access
|
98
|
-
|
99
|
-
:include: xpath_usage.intout
|
100
|
-
|
101
|
-
The objects supplied to the <tt>all()</tt>, <tt>first()</tt>, and
|
102
|
-
<tt>each()</tt> calls must be REXML element nodes, i.e. they must
|
103
|
-
support messages like <tt>elements</tt>, <tt>attributes</tt> etc
|
104
|
-
(instances of REXML::Element and its subclasses do this). The calls
|
105
|
-
return the found elements as instances of REXML::Element or
|
106
|
-
XML::XXPath::Accessors::Attribute. The latter is a wrapper around
|
107
|
-
attribute nodes that is largely call-compatible to
|
108
|
-
REXML::Element. This is so you can write things like
|
109
|
-
<tt>path.each{|node|puts node.text}</tt> without having to
|
110
|
-
special-case anything even if the path matches attributes, not just
|
111
|
-
elements.
|
112
|
-
|
113
|
-
As you can see, you can re-use path objects, applying them to
|
114
|
-
different XML elements at will. You should do this because the XPath
|
115
|
-
pattern is stored inside the XPath object in a pre-compiled form,
|
116
|
-
which makes it more efficient.
|
117
|
-
|
118
|
-
The path elements of the XPath pattern are applied to the
|
119
|
-
<tt>.elements</tt> collection of the passed XML element and its
|
120
|
-
sub-elements, starting with the first one. This is shown by the
|
121
|
-
following code:
|
122
|
-
|
123
|
-
:include: xpath_docvsroot.intout
|
124
|
-
|
125
|
-
A REXML +Document+ object is a REXML +Element+ object whose +elements+
|
126
|
-
collection consists only of a single member -- the document's root
|
127
|
-
node. The first path element of the XPath -- "foo" in the example --
|
128
|
-
is matched against that. That is why the path "/bar" in the example
|
129
|
-
doesn't match anything when matched against the document +d+ itself.
|
130
|
-
|
131
|
-
An ordinary REXML +Element+ object that represents a node somewhere
|
132
|
-
inside an XML tree has an +elements+ collection that consists of all
|
133
|
-
the element's direct sub-elements. That is why XPath patterns matched
|
134
|
-
against the +firstelt+ element in the example *must not* start with
|
135
|
-
"/first" (unless there is a child node that is also named "first").
|
136
|
-
|
137
|
-
|
138
|
-
=== Write Access
|
139
|
-
|
140
|
-
You may pass an <tt>:ensure_created=>true</tt> option argument to
|
141
|
-
_path_.first(_elt_)/_path_.all(_elt_) calls to make sure that _path_
|
142
|
-
exists inside the passed XML element _elt_. If it existed before,
|
143
|
-
nothing changes, and the call behaves just as it would without the
|
144
|
-
option argument. If the path didn't exist before, the XML element is
|
145
|
-
modified such that
|
146
|
-
|
147
|
-
- the path exists afterwards
|
148
|
-
|
149
|
-
- all paths that existed before still exist afterwards
|
150
|
-
|
151
|
-
- the modification is as small as possible (i.e. as few elements as
|
152
|
-
possible are added, additional attributes are added to existing
|
153
|
-
elements if possible etc.)
|
154
|
-
|
155
|
-
The created resp. previously existing, matching elements are returned.
|
156
|
-
|
157
|
-
|
158
|
-
Examples:
|
159
|
-
|
160
|
-
:include: xpath_ensure_created.intout
|
161
|
-
|
162
|
-
|
163
|
-
Alternatively, you may pass a <tt>:create_new=>true</tt> option
|
164
|
-
argument or call <tt>create_new</tt> (_path_.create_new(_elt_) is
|
165
|
-
equivalent to _path_.first(_elt_,:create_new=>true)). In that case, a
|
166
|
-
new node is created in _elt_ for each path element of _path_ (or an
|
167
|
-
exception raised if that wasn't possible for any path element).
|
168
|
-
|
169
|
-
Examples:
|
170
|
-
|
171
|
-
:include: xpath_create_new.intout
|
172
|
-
|
173
|
-
This feature is used in xml-mapping by node types like
|
174
|
-
XML::Mapping::ArrayNode, which must create a new instance of the
|
175
|
-
"per-array element path" for each element of the array to be stored in
|
176
|
-
an XML tree.
|
177
|
-
|
178
|
-
|
179
|
-
=== Pathological Cases
|
180
|
-
|
181
|
-
What is created when the Path "*" is to be created inside an empty XML
|
182
|
-
element? The name of the element to be created isn't known, but still
|
183
|
-
some element must be created. The answer is that xml-xxpath creates a
|
184
|
-
special "unspecified" element whose name must be set by the caller
|
185
|
-
afterwards:
|
186
|
-
|
187
|
-
:include: xpath_pathological.intout
|
188
|
-
|
189
|
-
The "newelt" object in the last example is an ordinary
|
190
|
-
REXML::Element. xml-xxpath mixes the "unspecified" attribute into that
|
191
|
-
class, as well as into the XML::XXPath::Accessors::Attribute class
|
192
|
-
mentioned above.
|
193
|
-
|
194
|
-
|
195
|
-
== Implentation notes
|
196
|
-
|
197
|
-
<tt>doc/xpath_impl_notes.txt</tt> contains some documentation on the
|
198
|
-
implementation of xml-xxpath.
|
199
|
-
|
200
|
-
== License
|
201
|
-
|
202
|
-
Ruby's.
|