rubysl-rexml 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/rexml/attlistdecl.rb +62 -0
- data/lib/rexml/attribute.rb +185 -0
- data/lib/rexml/cdata.rb +67 -0
- data/lib/rexml/child.rb +96 -0
- data/lib/rexml/comment.rb +80 -0
- data/lib/rexml/doctype.rb +271 -0
- data/lib/rexml/document.rb +230 -0
- data/lib/rexml/dtd/attlistdecl.rb +10 -0
- data/lib/rexml/dtd/dtd.rb +51 -0
- data/lib/rexml/dtd/elementdecl.rb +17 -0
- data/lib/rexml/dtd/entitydecl.rb +56 -0
- data/lib/rexml/dtd/notationdecl.rb +39 -0
- data/lib/rexml/element.rb +1227 -0
- data/lib/rexml/encoding.rb +71 -0
- data/lib/rexml/encodings/CP-1252.rb +103 -0
- data/lib/rexml/encodings/EUC-JP.rb +35 -0
- data/lib/rexml/encodings/ICONV.rb +22 -0
- data/lib/rexml/encodings/ISO-8859-1.rb +7 -0
- data/lib/rexml/encodings/ISO-8859-15.rb +72 -0
- data/lib/rexml/encodings/SHIFT-JIS.rb +37 -0
- data/lib/rexml/encodings/SHIFT_JIS.rb +1 -0
- data/lib/rexml/encodings/UNILE.rb +34 -0
- data/lib/rexml/encodings/US-ASCII.rb +30 -0
- data/lib/rexml/encodings/UTF-16.rb +35 -0
- data/lib/rexml/encodings/UTF-8.rb +18 -0
- data/lib/rexml/entity.rb +166 -0
- data/lib/rexml/formatters/default.rb +109 -0
- data/lib/rexml/formatters/pretty.rb +138 -0
- data/lib/rexml/formatters/transitive.rb +56 -0
- data/lib/rexml/functions.rb +382 -0
- data/lib/rexml/instruction.rb +70 -0
- data/lib/rexml/light/node.rb +196 -0
- data/lib/rexml/namespace.rb +47 -0
- data/lib/rexml/node.rb +75 -0
- data/lib/rexml/output.rb +24 -0
- data/lib/rexml/parent.rb +166 -0
- data/lib/rexml/parseexception.rb +51 -0
- data/lib/rexml/parsers/baseparser.rb +503 -0
- data/lib/rexml/parsers/lightparser.rb +60 -0
- data/lib/rexml/parsers/pullparser.rb +196 -0
- data/lib/rexml/parsers/sax2parser.rb +238 -0
- data/lib/rexml/parsers/streamparser.rb +46 -0
- data/lib/rexml/parsers/treeparser.rb +97 -0
- data/lib/rexml/parsers/ultralightparser.rb +56 -0
- data/lib/rexml/parsers/xpathparser.rb +698 -0
- data/lib/rexml/quickpath.rb +266 -0
- data/lib/rexml/rexml.rb +32 -0
- data/lib/rexml/sax2listener.rb +97 -0
- data/lib/rexml/source.rb +251 -0
- data/lib/rexml/streamlistener.rb +92 -0
- data/lib/rexml/syncenumerator.rb +33 -0
- data/lib/rexml/text.rb +344 -0
- data/lib/rexml/undefinednamespaceexception.rb +8 -0
- data/lib/rexml/validation/relaxng.rb +559 -0
- data/lib/rexml/validation/validation.rb +155 -0
- data/lib/rexml/validation/validationexception.rb +9 -0
- data/lib/rexml/xmldecl.rb +119 -0
- data/lib/rexml/xmltokens.rb +18 -0
- data/lib/rexml/xpath.rb +66 -0
- data/lib/rexml/xpath_parser.rb +792 -0
- data/lib/rubysl/rexml.rb +1 -0
- data/lib/rubysl/rexml/version.rb +5 -0
- data/rubysl-rexml.gemspec +23 -0
- data/spec/attribute/clone_spec.rb +10 -0
- data/spec/attribute/element_spec.rb +22 -0
- data/spec/attribute/equal_value_spec.rb +17 -0
- data/spec/attribute/hash_spec.rb +12 -0
- data/spec/attribute/initialize_spec.rb +28 -0
- data/spec/attribute/inspect_spec.rb +19 -0
- data/spec/attribute/namespace_spec.rb +23 -0
- data/spec/attribute/node_type_spec.rb +9 -0
- data/spec/attribute/prefix_spec.rb +17 -0
- data/spec/attribute/remove_spec.rb +19 -0
- data/spec/attribute/to_s_spec.rb +13 -0
- data/spec/attribute/to_string_spec.rb +14 -0
- data/spec/attribute/value_spec.rb +14 -0
- data/spec/attribute/write_spec.rb +22 -0
- data/spec/attribute/xpath_spec.rb +19 -0
- data/spec/attributes/add_spec.rb +6 -0
- data/spec/attributes/append_spec.rb +6 -0
- data/spec/attributes/delete_all_spec.rb +30 -0
- data/spec/attributes/delete_spec.rb +26 -0
- data/spec/attributes/each_attribute_spec.rb +24 -0
- data/spec/attributes/each_spec.rb +24 -0
- data/spec/attributes/element_reference_spec.rb +18 -0
- data/spec/attributes/element_set_spec.rb +25 -0
- data/spec/attributes/get_attribute_ns_spec.rb +13 -0
- data/spec/attributes/get_attribute_spec.rb +28 -0
- data/spec/attributes/initialize_spec.rb +18 -0
- data/spec/attributes/length_spec.rb +6 -0
- data/spec/attributes/namespaces_spec.rb +5 -0
- data/spec/attributes/prefixes_spec.rb +23 -0
- data/spec/attributes/shared/add.rb +17 -0
- data/spec/attributes/shared/length.rb +12 -0
- data/spec/attributes/size_spec.rb +6 -0
- data/spec/attributes/to_a_spec.rb +20 -0
- data/spec/cdata/clone_spec.rb +9 -0
- data/spec/cdata/initialize_spec.rb +24 -0
- data/spec/cdata/shared/to_s.rb +11 -0
- data/spec/cdata/to_s_spec.rb +6 -0
- data/spec/cdata/value_spec.rb +6 -0
- data/spec/document/add_element_spec.rb +30 -0
- data/spec/document/add_spec.rb +60 -0
- data/spec/document/clone_spec.rb +19 -0
- data/spec/document/doctype_spec.rb +14 -0
- data/spec/document/encoding_spec.rb +21 -0
- data/spec/document/expanded_name_spec.rb +15 -0
- data/spec/document/new_spec.rb +37 -0
- data/spec/document/node_type_spec.rb +7 -0
- data/spec/document/root_spec.rb +11 -0
- data/spec/document/stand_alone_spec.rb +18 -0
- data/spec/document/version_spec.rb +13 -0
- data/spec/document/write_spec.rb +38 -0
- data/spec/document/xml_decl_spec.rb +14 -0
- data/spec/element/add_attribute_spec.rb +40 -0
- data/spec/element/add_attributes_spec.rb +21 -0
- data/spec/element/add_element_spec.rb +38 -0
- data/spec/element/add_namespace_spec.rb +23 -0
- data/spec/element/add_text_spec.rb +23 -0
- data/spec/element/attribute_spec.rb +16 -0
- data/spec/element/attributes_spec.rb +18 -0
- data/spec/element/cdatas_spec.rb +23 -0
- data/spec/element/clone_spec.rb +28 -0
- data/spec/element/comments_spec.rb +20 -0
- data/spec/element/delete_attribute_spec.rb +38 -0
- data/spec/element/delete_element_spec.rb +50 -0
- data/spec/element/delete_namespace_spec.rb +24 -0
- data/spec/element/document_spec.rb +17 -0
- data/spec/element/each_element_with_attribute_spec.rb +34 -0
- data/spec/element/each_element_with_text_spec.rb +30 -0
- data/spec/element/get_text_spec.rb +17 -0
- data/spec/element/has_attributes_spec.rb +16 -0
- data/spec/element/has_elements_spec.rb +17 -0
- data/spec/element/has_text_spec.rb +15 -0
- data/spec/element/inspect_spec.rb +26 -0
- data/spec/element/instructions_spec.rb +20 -0
- data/spec/element/namespace_spec.rb +26 -0
- data/spec/element/namespaces_spec.rb +31 -0
- data/spec/element/new_spec.rb +34 -0
- data/spec/element/next_element_spec.rb +18 -0
- data/spec/element/node_type_spec.rb +7 -0
- data/spec/element/prefixes_spec.rb +22 -0
- data/spec/element/previous_element_spec.rb +19 -0
- data/spec/element/raw_spec.rb +23 -0
- data/spec/element/root_spec.rb +27 -0
- data/spec/element/text_spec.rb +45 -0
- data/spec/element/texts_spec.rb +15 -0
- data/spec/element/whitespace_spec.rb +22 -0
- data/spec/node/each_recursive_spec.rb +20 -0
- data/spec/node/find_first_recursive_spec.rb +24 -0
- data/spec/node/index_in_parent_spec.rb +14 -0
- data/spec/node/next_sibling_node_spec.rb +20 -0
- data/spec/node/parent_spec.rb +20 -0
- data/spec/node/previous_sibling_node_spec.rb +20 -0
- data/spec/shared/each_element.rb +35 -0
- data/spec/shared/elements_to_a.rb +35 -0
- data/spec/text/append_spec.rb +9 -0
- data/spec/text/clone_spec.rb +9 -0
- data/spec/text/comparison_spec.rb +24 -0
- data/spec/text/empty_spec.rb +11 -0
- data/spec/text/indent_text_spec.rb +23 -0
- data/spec/text/inspect_spec.rb +7 -0
- data/spec/text/new_spec.rb +48 -0
- data/spec/text/node_type_spec.rb +7 -0
- data/spec/text/normalize_spec.rb +7 -0
- data/spec/text/read_with_substitution_spec.rb +12 -0
- data/spec/text/to_s_spec.rb +17 -0
- data/spec/text/unnormalize_spec.rb +7 -0
- data/spec/text/value_spec.rb +36 -0
- data/spec/text/wrap_spec.rb +20 -0
- data/spec/text/write_with_substitution_spec.rb +32 -0
- metadata +385 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#delete_namespace" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@doc = REXML::Document.new "<a xmlns:foo='bar' xmlns='twiddle'/>"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "deletes a namespace from the element" do
|
10
|
+
@doc.root.delete_namespace 'foo'
|
11
|
+
@doc.root.namespace("foo").should be_nil
|
12
|
+
@doc.root.to_s.should == "<a xmlns='twiddle'/>"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "deletes default namespace when called with no args" do
|
16
|
+
@doc.root.delete_namespace
|
17
|
+
@doc.root.namespace.should be_empty
|
18
|
+
@doc.root.to_s.should == "<a xmlns:foo='bar'/>"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the element" do
|
22
|
+
@doc.root.delete_namespace.should == @doc.root
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#document" do
|
4
|
+
|
5
|
+
it "returns the element's document" do
|
6
|
+
d = REXML::Document.new("<root><elem/></root>")
|
7
|
+
d << REXML::XMLDecl.new
|
8
|
+
d.root.document.should == d
|
9
|
+
d.root.document.to_s.should == d.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns nil if it belongs to no document" do
|
13
|
+
REXML::Element.new("standalone").document.should be_nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#each_element_with_attributes" do
|
4
|
+
before :each do
|
5
|
+
@document = REXML::Element.new("people")
|
6
|
+
@father = REXML::Element.new("Person")
|
7
|
+
@father.attributes["name"] = "Joe"
|
8
|
+
@son = REXML::Element.new("Child")
|
9
|
+
@son.attributes["name"] = "Fred"
|
10
|
+
@document.root << @father
|
11
|
+
@document.root << @son
|
12
|
+
@childs = []
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns childs with attribute" do
|
16
|
+
@document.each_element_with_attribute("name") { |elem| @childs << elem }
|
17
|
+
@childs[0].should == @father
|
18
|
+
@childs[1].should == @son
|
19
|
+
end
|
20
|
+
|
21
|
+
it "takes attribute value as second argument" do
|
22
|
+
@document.each_element_with_attribute("name", "Fred"){ |elem| elem.should == @son }
|
23
|
+
end
|
24
|
+
|
25
|
+
it "takes max number of childs as third argument" do
|
26
|
+
@document.each_element_with_attribute("name", nil, 1) { |elem| @childs << elem }
|
27
|
+
@childs.size.should == 1
|
28
|
+
@childs[0].should == @father
|
29
|
+
end
|
30
|
+
|
31
|
+
it "takes XPath filter as fourth argument" do
|
32
|
+
@document.each_element_with_attribute("name", nil, 0, "Child"){ |elem| elem.should == @son}
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#each_element_with_text" do
|
4
|
+
before :each do
|
5
|
+
@document = REXML::Element.new("people")
|
6
|
+
|
7
|
+
@joe = REXML::Element.new("Person")
|
8
|
+
@joe.text = "Joe"
|
9
|
+
@fred = REXML::Element.new("Person")
|
10
|
+
@fred.text = "Fred"
|
11
|
+
@another = REXML::Element.new("AnotherPerson")
|
12
|
+
@another.text = "Fred"
|
13
|
+
@document.root << @joe
|
14
|
+
@document.root << @fred
|
15
|
+
@document.root << @another
|
16
|
+
@childs = []
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns childs with text" do
|
20
|
+
@document.each_element_with_text("Joe"){|c| c.should == @joe}
|
21
|
+
end
|
22
|
+
|
23
|
+
it "takes max as second argument" do
|
24
|
+
@document.each_element_with_text("Fred", 1){ |c| c.should == @fred}
|
25
|
+
end
|
26
|
+
|
27
|
+
it "takes XPath filter as third argument" do
|
28
|
+
@document.each_element_with_text("Fred", 0, "Person"){ |c| c.should == @fred}
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#get_text" do
|
4
|
+
before :each do
|
5
|
+
@doc = REXML::Document.new "<p>some text<b>this is bold!</b> more text</p>"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns the first text child node" do
|
9
|
+
@doc.root.get_text.value.should == "some text"
|
10
|
+
@doc.root.get_text.should be_kind_of(REXML::Text)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns text from an element matching path" do
|
14
|
+
@doc.root.get_text("b").value.should == "this is bold!"
|
15
|
+
@doc.root.get_text("b").should be_kind_of(REXML::Text)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#has_attributes?" do
|
4
|
+
before :each do
|
5
|
+
@e = REXML::Element.new("test_elem")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns true when element has any attributes" do
|
9
|
+
@e.add_attribute("name", "Joe")
|
10
|
+
@e.has_attributes?.should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false if element has no attributes" do
|
14
|
+
@e.has_attributes?.should be_false
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#has_elements?" do
|
4
|
+
before :each do
|
5
|
+
@e = REXML::Element.new("root")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns true if element has child elements" do
|
9
|
+
child = REXML::Element.new("child")
|
10
|
+
@e << child
|
11
|
+
@e.has_elements?.should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns false if element doesn't have child elements" do
|
15
|
+
@e.has_elements?.should be_false
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#has_text?" do
|
4
|
+
|
5
|
+
it "returns true if element has a Text child" do
|
6
|
+
e = REXML::Element.new("Person")
|
7
|
+
e.text = "My text"
|
8
|
+
e.has_text?.should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns false if it has no Text childs" do
|
12
|
+
e = REXML::Element.new("Person")
|
13
|
+
e.has_text?.should be_false
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#inspect" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@name = REXML::Element.new "name"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the node as a string" do
|
10
|
+
@name.inspect.should == "<name/>"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "inserts '...' if the node has children" do
|
14
|
+
e = REXML::Element.new "last_name"
|
15
|
+
@name << e
|
16
|
+
@name.inspect.should == "<name> ... </>"
|
17
|
+
# This might make more sense but differs from MRI's default behavior
|
18
|
+
# @name.inspect.should == "<name> ... </name>"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "inserts the attributes in the string" do
|
22
|
+
@name.add_attribute "language"
|
23
|
+
@name.attributes["language"] = "english"
|
24
|
+
@name.inspect.should == "<name language='english'/>"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#instructions" do
|
4
|
+
before :each do
|
5
|
+
@elem = REXML::Element.new("root")
|
6
|
+
end
|
7
|
+
it "returns the Instruction children nodes" do
|
8
|
+
inst = REXML::Instruction.new("xml-stylesheet", "href='headlines.css'")
|
9
|
+
@elem << inst
|
10
|
+
@elem.instructions.first.should == inst
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns an empty array if it has no Instruction children" do
|
14
|
+
@elem.instructions.should be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
it "freezes the returned array" do
|
18
|
+
@elem.instructions.frozen?.should be_true
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#namespace" do
|
4
|
+
before :each do
|
5
|
+
@doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
|
6
|
+
@elem = @doc.elements["//b"]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the default namespace" do
|
10
|
+
@elem.namespace.should == "1"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "accepts a namespace prefix" do
|
14
|
+
@elem.namespace("y").should == "2"
|
15
|
+
@doc.elements["//c"].namespace("z").should == "3"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns an empty String if default namespace is not defined" do
|
19
|
+
e = REXML::Document.new("<a/>")
|
20
|
+
e.root.namespace.should be_empty
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns nil if namespace is not defined" do
|
24
|
+
@elem.namespace("z").should be_nil
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#namespaces" do
|
4
|
+
before :each do
|
5
|
+
doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
|
6
|
+
@elem = doc.elements["//c"]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns a hash of the namespaces" do
|
10
|
+
ns = {"y"=>"2", "z"=>"3", "xmlns"=>"1"}
|
11
|
+
@elem.namespaces.keys.sort.should == ns.keys.sort
|
12
|
+
@elem.namespaces.values.sort.should == ns.values.sort
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns an empty hash if no namespaces exist" do
|
16
|
+
e = REXML::Element.new "element"
|
17
|
+
e.namespaces.kind_of?(Hash).should == true
|
18
|
+
e.namespaces.should be_empty
|
19
|
+
end
|
20
|
+
|
21
|
+
it "uses namespace prefixes as keys" do
|
22
|
+
prefixes = ["y", "z", "xmlns"]
|
23
|
+
@elem.namespaces.keys.sort.should == prefixes.sort
|
24
|
+
end
|
25
|
+
|
26
|
+
it "uses namespace values as the hash values" do
|
27
|
+
values = ["2", "3", "1"]
|
28
|
+
@elem.namespaces.values.sort.should == values.sort
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#new" do
|
4
|
+
|
5
|
+
it "creates element from tag name" do
|
6
|
+
REXML::Element.new("foo").name.should == "foo"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "creates element with default attributes" do
|
10
|
+
e = REXML::Element.new
|
11
|
+
e.name.should == REXML::Element::UNDEFINED
|
12
|
+
e.context.should == nil
|
13
|
+
e.parent.should == nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "creates element from another element" do
|
17
|
+
e = REXML::Element.new "foo"
|
18
|
+
f = REXML::Element.new e
|
19
|
+
e.name.should == f.name
|
20
|
+
e.context.should == f.context
|
21
|
+
e.parent.should == f.parent
|
22
|
+
end
|
23
|
+
|
24
|
+
it "takes parent as second argument" do
|
25
|
+
parent = REXML::Element.new "foo"
|
26
|
+
child = REXML::Element.new "bar", parent
|
27
|
+
child.parent.should == parent
|
28
|
+
end
|
29
|
+
|
30
|
+
it "takes context as third argument" do
|
31
|
+
context = {"some_key" => "some_value"}
|
32
|
+
REXML::Element.new("foo", nil, context).context.should == context
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#next_element" do
|
4
|
+
before :each do
|
5
|
+
@a = REXML::Element.new "a"
|
6
|
+
@b = REXML::Element.new "b"
|
7
|
+
@c = REXML::Element.new "c"
|
8
|
+
@a.root << @b
|
9
|
+
@a.root << @c
|
10
|
+
end
|
11
|
+
it "returns next existing element" do
|
12
|
+
@a.elements["b"].next_element.should == @c
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns nil on last element" do
|
16
|
+
@a.elements["c"].next_element.should == nil
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#prefixes" do
|
4
|
+
before :each do
|
5
|
+
doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
|
6
|
+
@elem = doc.elements["//c"]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns an array of the prefixes of the namespaces" do
|
10
|
+
@elem.prefixes.should == ["y", "z"]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not include the default namespace" do
|
14
|
+
@elem.prefixes.include?("xmlns").should == false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns an empty array if no namespace was defined" do
|
18
|
+
doc = REXML::Document.new "<root><something/></root>"
|
19
|
+
root = doc.elements["//root"]
|
20
|
+
root.prefixes.should == []
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#previous_element" do
|
4
|
+
before :each do
|
5
|
+
@a = REXML::Element.new "a"
|
6
|
+
@b = REXML::Element.new "b"
|
7
|
+
@c = REXML::Element.new "c"
|
8
|
+
@a.root << @b
|
9
|
+
@a.root << @c
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns previous element" do
|
13
|
+
@a.elements["c"].previous_element.should == @b
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns nil on first element" do
|
17
|
+
@a.elements["b"].previous_element.should == nil
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#raw" do
|
4
|
+
it "returns true if raw mode is set to all" do
|
5
|
+
REXML::Element.new("MyElem", nil, {:raw => :all}).raw.should == true
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns true if raw mode is set to expanded_name" do
|
9
|
+
REXML::Element.new("MyElem", nil, {:raw => "MyElem"}).raw.should == true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns false if raw mode is not set" do
|
13
|
+
REXML::Element.new("MyElem", nil, {:raw => ""}).raw.should == false
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns false if raw is not :all or expanded_name" do
|
17
|
+
REXML::Element.new("MyElem", nil, {:raw => "Something"}).raw.should == false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns nil if context is not set" do
|
21
|
+
REXML::Element.new("MyElem").raw.should == nil
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
describe "REXML::Element#root" do
|
4
|
+
before :each do
|
5
|
+
@doc = REXML::Document.new
|
6
|
+
@root = REXML::Element.new "root"
|
7
|
+
@node = REXML::Element.new "node"
|
8
|
+
@doc << @root << @node
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns first child on documents" do
|
12
|
+
@doc.root.should == @root
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns self on root nodes" do
|
16
|
+
@root.root.should == @root
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns parent's root on child nodes" do
|
20
|
+
@node.root.should == @root
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns self on standalone nodes" do
|
24
|
+
e = REXML::Element.new "Elem" # Note that it doesn't have a parent node
|
25
|
+
e.root.should == e
|
26
|
+
end
|
27
|
+
end
|