xml-smart 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example/xpath_visual +1 -1
- data/lib/xml/smart_dom.rb +9 -9
- data/lib/xml/smart_domelement.rb +8 -0
- data/lib/xml/smart_domnamespaceset.rb +4 -4
- data/lib/xml/smart_domother.rb +3 -3
- data/test/EXAMPLE.xml +1 -1
- data/test/tc_namespace_default.rb +6 -6
- data/xml-smart.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97b3d4716521c2db8484f9bcfbfbf3e94f6860fcca2edef1525f5e6bb72e6a06
|
4
|
+
data.tar.gz: 25dfd08f00306769c64fd556d9f589aa649bf2760c32f0acfe07f5dbb7df9e48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2764ddbf57f7b2ef45e07da667fa9a4f32fb505633a559e5ef759af9ac7c5b7482a93a367f3d8ab9b08bb82b9350211016d18a2f5fd98cdad8e5f7869424ea9b
|
7
|
+
data.tar.gz: 7a0c5de212141c7e1d86864c1880d1f997aa943cb87adc72f1c8df12000234393d72fef4ef6d04b7fe3953c31716ced533aee44d19557d37c7d73612b93f6909
|
data/example/xpath_visual
CHANGED
data/lib/xml/smart_dom.rb
CHANGED
@@ -13,7 +13,7 @@ module XML
|
|
13
13
|
Element.new(@dom.root)
|
14
14
|
end
|
15
15
|
def root=(nr)
|
16
|
-
@dom.root.replace(nr.instance_variable_get(:@
|
16
|
+
@dom.root.replace(nr.instance_variable_get(:@node)) if nr.instance_of? Element
|
17
17
|
end
|
18
18
|
|
19
19
|
def find(path)
|
@@ -70,20 +70,20 @@ module XML
|
|
70
70
|
|
71
71
|
def xinclude!(basedir=nil)
|
72
72
|
Element.new(@dom.root).xinclude!(basedir)
|
73
|
-
end
|
73
|
+
end
|
74
74
|
|
75
75
|
def self::smart_helper(node)
|
76
76
|
if node.instance_of? Nokogiri::XML::Element
|
77
77
|
XML::Smart::Dom::Element.new(node)
|
78
78
|
elsif node.instance_of? Nokogiri::XML::Attr
|
79
79
|
XML::Smart::Dom::Attribute.new(node)
|
80
|
-
elsif node.instance_of? Nokogiri::XML::NodeSet
|
80
|
+
elsif node.instance_of? Nokogiri::XML::NodeSet
|
81
81
|
XML::Smart::Dom::NodeSet.new(node)
|
82
|
-
elsif node.instance_of?(String) || node.instance_of?(TrueClass) || node.instance_of?(FalseClass) || node.instance_of?(Float)
|
82
|
+
elsif node.instance_of?(String) || node.instance_of?(TrueClass) || node.instance_of?(FalseClass) || node.instance_of?(Float)
|
83
83
|
node
|
84
|
-
elsif node.instance_of? Nokogiri::XML::Text
|
84
|
+
elsif node.instance_of? Nokogiri::XML::Text
|
85
85
|
XML::Smart::Dom::Text.new(node)
|
86
|
-
elsif node.instance_of? Nokogiri::XML::Namespace
|
86
|
+
elsif node.instance_of? Nokogiri::XML::Namespace
|
87
87
|
XML::Smart::Dom::Namespace.new(node)
|
88
88
|
elsif node.instance_of? Nokogiri::XML::Document
|
89
89
|
XML::Smart::Dom.new(node)
|
@@ -93,7 +93,7 @@ module XML
|
|
93
93
|
nil
|
94
94
|
else
|
95
95
|
XML::Smart::Dom::Other.new(node)
|
96
|
-
end
|
96
|
+
end
|
97
97
|
end
|
98
98
|
|
99
99
|
def validate_against(doc,&errbl)
|
@@ -114,9 +114,9 @@ module XML
|
|
114
114
|
res = Nokogiri::XSLT::Stylesheet.parse_stylesheet_doc(doc.instance_variable_get(:@dom)).transform(@dom,params)
|
115
115
|
if res.children.length != 0 && res.children.first.class == Nokogiri::XML::Text
|
116
116
|
Text.new(res.children.first).text
|
117
|
-
else
|
117
|
+
else
|
118
118
|
Dom::smart_helper(res)
|
119
|
-
end
|
119
|
+
end
|
120
120
|
end
|
121
121
|
|
122
122
|
end
|
data/lib/xml/smart_domelement.rb
CHANGED
@@ -171,6 +171,14 @@ module XML
|
|
171
171
|
end
|
172
172
|
|
173
173
|
def replace_by(n)
|
174
|
+
case n
|
175
|
+
when Element; Element.new @node.replace(n.instance_variable_get(:@node))
|
176
|
+
when NodeSet; NodeSet.new @node.replace(n.instance_variable_get(:@nodeset))
|
177
|
+
else
|
178
|
+
nil
|
179
|
+
end
|
180
|
+
end
|
181
|
+
def replace_by_copy(n)
|
174
182
|
case n
|
175
183
|
when Element; Element.new @node.replace(n.instance_variable_get(:@node).dup)
|
176
184
|
when NodeSet; NodeSet.new @node.replace(n.instance_variable_get(:@nodeset).dup)
|
@@ -45,7 +45,7 @@ module XML
|
|
45
45
|
nnew.add(nold.children)
|
46
46
|
nold.replace_by(nnew)
|
47
47
|
@node = nnod
|
48
|
-
@parent.instance_variable_set(:@
|
48
|
+
@parent.instance_variable_set(:@node,@node)
|
49
49
|
@node.document.custom_namespace_prefixes_update
|
50
50
|
@node.document.ns_update
|
51
51
|
Namespace.new(ns)
|
@@ -64,7 +64,7 @@ module XML
|
|
64
64
|
nnew.add(nold.children)
|
65
65
|
nold.replace_by(nnew)
|
66
66
|
@node = nnod
|
67
|
-
@parent.instance_variable_set(:@
|
67
|
+
@parent.instance_variable_set(:@node,@node)
|
68
68
|
@node.document.custom_namespace_prefixes_update
|
69
69
|
@node.document.ns_update
|
70
70
|
nil
|
@@ -92,7 +92,7 @@ module XML
|
|
92
92
|
nnew.add(nold.children)
|
93
93
|
nold.replace_by(nnew)
|
94
94
|
@node = nnod
|
95
|
-
@parent.instance_variable_set(:@
|
95
|
+
@parent.instance_variable_set(:@node,@node)
|
96
96
|
@node.document.custom_namespace_prefixes_update
|
97
97
|
@node.document.ns_update
|
98
98
|
true
|
@@ -115,7 +115,7 @@ module XML
|
|
115
115
|
nnew.add(nold.children)
|
116
116
|
nold.replace_by(nnew)
|
117
117
|
@node = nnod
|
118
|
-
@parent.instance_variable_set(:@
|
118
|
+
@parent.instance_variable_set(:@node,@node)
|
119
119
|
@node.document.custom_namespace_prefixes_update
|
120
120
|
@node.document.ns_update
|
121
121
|
self
|
data/lib/xml/smart_domother.rb
CHANGED
data/test/EXAMPLE.xml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<test xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xml:lang="de">
|
2
2
|
<names>
|
3
|
-
<name team="0" a="3">
|
3
|
+
<name team="0" a="3">2020-06-05 23:34:48 +0200</name>
|
4
4
|
<name team="1">Jürgen</name>
|
5
5
|
<name team="1">Michel</name>
|
6
6
|
<name team="1">Raphi</name>
|
@@ -12,7 +12,7 @@ class TestNamespaceDefault < Minitest::Test
|
|
12
12
|
assert(doc.namespaces.length == 2)
|
13
13
|
assert(doc.namespaces.key? 'soap')
|
14
14
|
assert(doc.namespaces.key? 'x')
|
15
|
-
|
15
|
+
|
16
16
|
# add an element hallo to root
|
17
17
|
nsnode = doc.root.add("hallo")
|
18
18
|
|
@@ -50,7 +50,7 @@ class TestNamespaceDefault < Minitest::Test
|
|
50
50
|
nsnode.namespaces.add("aaa","http://heise2")
|
51
51
|
|
52
52
|
assert(nsnode.namespaces[nil] == nil)
|
53
|
-
|
53
|
+
|
54
54
|
nsnode.namespaces.add(nil,"http://heise")
|
55
55
|
nsnode.namespaces[nil] = "http://heiser"
|
56
56
|
|
@@ -61,13 +61,13 @@ class TestNamespaceDefault < Minitest::Test
|
|
61
61
|
assert(nsnode.namespaces['xmlns'].href == "http://heiser")
|
62
62
|
assert(nsnode.namespaces['aaa'].href == "http://heise2")
|
63
63
|
assert(nsnode.namespaces['test'].href == "http://heise1")
|
64
|
-
|
64
|
+
|
65
65
|
assert(doc.namespaces.length == 5)
|
66
66
|
nsnode.namespaces.delete_at('aaa')
|
67
67
|
assert(nsnode.namespaces['aaa'].nil?)
|
68
|
-
|
68
|
+
|
69
69
|
assert(doc.namespaces.length == 4)
|
70
70
|
nsnode.namespaces.delete_all!
|
71
71
|
assert(doc.namespaces.length == 2)
|
72
|
-
end
|
73
|
-
end
|
72
|
+
end
|
73
|
+
end
|
data/xml-smart.gemspec
CHANGED