xml_node_stream 1.0.0 → 2.0.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/CHANGELOG.md +30 -0
- data/README.md +139 -0
- data/VERSION +1 -1
- data/lib/xml_node_stream/http_stream.rb +179 -0
- data/lib/xml_node_stream/node.rb +98 -47
- data/lib/xml_node_stream/parser/base.rb +49 -12
- data/lib/xml_node_stream/parser/libxml_parser.rb +38 -11
- data/lib/xml_node_stream/parser/nokogiri_parser.rb +50 -12
- data/lib/xml_node_stream/parser/rexml_parser.rb +35 -8
- data/lib/xml_node_stream/parser.rb +54 -29
- data/lib/xml_node_stream/selector.rb +144 -34
- data/lib/xml_node_stream.rb +18 -5
- data/xml_node_stream.gemspec +33 -62
- metadata +47 -73
- data/README.rdoc +0 -61
- data/Rakefile +0 -42
- data/init.rb +0 -1
- data/spec/node_spec.rb +0 -140
- data/spec/parser_spec.rb +0 -148
- data/spec/selector_spec.rb +0 -73
- data/spec/spec_helper.rb +0 -3
- data/spec/test.xml +0 -57
- data/spec/xml_node_stream_spec.rb +0 -11
- /data/{MIT_LICENSE → MIT-LICENSE} +0 -0
data/spec/selector_spec.rb
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
|
2
|
-
|
|
3
|
-
describe XmlNodeStream::Selector do
|
|
4
|
-
|
|
5
|
-
before :each do
|
|
6
|
-
@root = XmlNodeStream::Node.new("root")
|
|
7
|
-
@child_1 = XmlNodeStream::Node.new("child", @root)
|
|
8
|
-
@child_2 = XmlNodeStream::Node.new("child", @root)
|
|
9
|
-
@grandchild_1 = XmlNodeStream::Node.new("grandchild", @child_1, nil, "val1")
|
|
10
|
-
@grandchild_2 = XmlNodeStream::Node.new("grandchild", @child_1, nil, "val2")
|
|
11
|
-
@grandchild_3 = XmlNodeStream::Node.new("grandchild", @child_2, nil, "val3")
|
|
12
|
-
@grandchild_4 = XmlNodeStream::Node.new("grandchild", @child_2, nil, "val4")
|
|
13
|
-
@great_grandchild = XmlNodeStream::Node.new("grandchild", @grandchild_1, nil, "val1.a")
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "should find child nodes with a specified name" do
|
|
17
|
-
selector = XmlNodeStream::Selector.new("child")
|
|
18
|
-
selector.find(@root).should == [@child_1, @child_2]
|
|
19
|
-
selector = XmlNodeStream::Selector.new("./child")
|
|
20
|
-
selector.find(@root).should == [@child_1, @child_2]
|
|
21
|
-
selector = XmlNodeStream::Selector.new("nothing")
|
|
22
|
-
selector.find(@root).should == []
|
|
23
|
-
selector.find(@child_1).should == []
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "should find descendant nodes with a specified name" do
|
|
27
|
-
selector = XmlNodeStream::Selector.new(".//grandchild")
|
|
28
|
-
selector.find(@root).should == [@grandchild_1, @grandchild_2, @grandchild_3, @grandchild_4, @great_grandchild]
|
|
29
|
-
selector.find(@child_1).should == [@great_grandchild]
|
|
30
|
-
selector.find(@child_2).should == []
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should find child nodes in a specified hierarchy" do
|
|
34
|
-
selector = XmlNodeStream::Selector.new("child/grandchild")
|
|
35
|
-
selector.find(@root).should == [@grandchild_1, @grandchild_2, @grandchild_3, @grandchild_4]
|
|
36
|
-
selector = XmlNodeStream::Selector.new("child/nothing")
|
|
37
|
-
selector.find(@root).should == []
|
|
38
|
-
selector.find(@child_1).should == []
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "should find an node itself" do
|
|
42
|
-
selector = XmlNodeStream::Selector.new(".")
|
|
43
|
-
selector.find(@child_1).should == [@child_1]
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "should find a parent node" do
|
|
47
|
-
selector = XmlNodeStream::Selector.new("..")
|
|
48
|
-
selector.find(@child_1).should == [@root]
|
|
49
|
-
selector.find(@root).should == []
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "should find an node's value" do
|
|
53
|
-
selector = XmlNodeStream::Selector.new("text()")
|
|
54
|
-
selector.find(@child_1).should == [nil]
|
|
55
|
-
selector.find(@grandchild_1).should == ["val1"]
|
|
56
|
-
selector = XmlNodeStream::Selector.new("child/grandchild/text()")
|
|
57
|
-
selector.find(@root).should == ["val1", "val2", "val3", "val4"]
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "should allow wildcards in the hierarchy" do
|
|
61
|
-
selector = XmlNodeStream::Selector.new("*/grandchild")
|
|
62
|
-
selector.find(@root).should == [@grandchild_1, @grandchild_2, @grandchild_3, @grandchild_4]
|
|
63
|
-
selector.find(@child_1).should == [@great_grandchild]
|
|
64
|
-
selector.find(@child_2).should == []
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "should find using full paths" do
|
|
68
|
-
selector = XmlNodeStream::Selector.new("/root/child")
|
|
69
|
-
selector.find(@root).should == [@child_1, @child_2]
|
|
70
|
-
selector.find(@grandchild_1).should == [@child_1, @child_2]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
end
|
data/spec/spec_helper.rb
DELETED
data/spec/test.xml
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0"?>
|
|
2
|
-
<library>
|
|
3
|
-
<?library-info version="2.0" ignore="yes" ?>
|
|
4
|
-
<!-- Authors -->
|
|
5
|
-
<authors>
|
|
6
|
-
<author id="1">
|
|
7
|
-
<name>Edward Gibbon</name>
|
|
8
|
-
</author>
|
|
9
|
-
<author id="2">
|
|
10
|
-
<name>Herman Melville</name>
|
|
11
|
-
</author>
|
|
12
|
-
<author id="3">
|
|
13
|
-
<name>Jack London</name>
|
|
14
|
-
</author>
|
|
15
|
-
</authors>
|
|
16
|
-
<!-- Books -->
|
|
17
|
-
<collection>
|
|
18
|
-
<section id="100" name="History">
|
|
19
|
-
<book id="1">
|
|
20
|
-
<title>
|
|
21
|
-
The Decline & Fall of the Roman Empire
|
|
22
|
-
</title>
|
|
23
|
-
<author id="1"/>
|
|
24
|
-
<abstract><![CDATA[History of the fall of Rome.]]></abstract>
|
|
25
|
-
<volumes>6</volumes>
|
|
26
|
-
</book>
|
|
27
|
-
</section>
|
|
28
|
-
<section id="200" name="Fiction">
|
|
29
|
-
<book id="2">
|
|
30
|
-
<title>
|
|
31
|
-
Call of the Wild
|
|
32
|
-
</title>
|
|
33
|
-
<author id="3"/>
|
|
34
|
-
<abstract><![CDATA[
|
|
35
|
-
A dog goes to Alaska.
|
|
36
|
-
]]></abstract>
|
|
37
|
-
</book>
|
|
38
|
-
<book id="3">
|
|
39
|
-
<title>
|
|
40
|
-
White Fang
|
|
41
|
-
</title>
|
|
42
|
-
<author id="3"/>
|
|
43
|
-
<abstract><![CDATA[Dogs, wolves, etc.]]></abstract>
|
|
44
|
-
</book>
|
|
45
|
-
<book id="4">
|
|
46
|
-
<title>
|
|
47
|
-
Moby Dick
|
|
48
|
-
</title>
|
|
49
|
-
<alternate_title>
|
|
50
|
-
The Whale
|
|
51
|
-
</alternate_title>
|
|
52
|
-
<author id="2"/>
|
|
53
|
-
<abstract><![CDATA[A mad captain seeks a mysterious white whale.]]></abstract>
|
|
54
|
-
</book>
|
|
55
|
-
</section>
|
|
56
|
-
</collection>
|
|
57
|
-
</library>
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
|
2
|
-
|
|
3
|
-
describe XmlNodeStream do
|
|
4
|
-
|
|
5
|
-
it "should parse a document using the Parser.parse method" do
|
|
6
|
-
block = lambda{}
|
|
7
|
-
XmlNodeStream::Parser.should_receive(:parse).with("<xml/>", &block)
|
|
8
|
-
XmlNodeStream.parse("<xml/>", &block)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
end
|
|
File without changes
|