This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
== Element Context
|
||||
|
||||
Notes:
|
||||
- All code on this page presupposes that the following has been executed:
|
||||
|
||||
require 'rexml/document'
|
||||
|
||||
- For convenience, examples on this page use +REXML::Document.new+, not +REXML::Element.new+.
|
||||
This is completely valid, because REXML::Document is a subclass of REXML::Element.
|
||||
|
||||
The context for an element is a hash of processing directives
|
||||
that influence the way \XML is read, stored, and written.
|
||||
The context entries are:
|
||||
|
||||
- +:respect_whitespace+: controls treatment of whitespace.
|
||||
- +:compress_whitespace+: determines whether whitespace is compressed.
|
||||
- +:ignore_whitespace_nodes+: determines whether whitespace-only nodes are to be ignored.
|
||||
- +:raw+: controls treatment of special characters and entities.
|
||||
|
||||
The default context for a new element is <tt>{}</tt>.
|
||||
You can set the context at element-creation time:
|
||||
|
||||
d = REXML::Document.new('', {compress_whitespace: :all, raw: :all})
|
||||
d.context # => {:compress_whitespace=>:all, :raw=>:all}
|
||||
|
||||
You can reset the entire context by assigning a new hash:
|
||||
|
||||
d.context = {ignore_whitespace_nodes: :all}
|
||||
d.context # => {:ignore_whitespace_nodes=>:all}
|
||||
|
||||
Or you can create or modify an individual entry:
|
||||
|
||||
d.context[:raw] = :all
|
||||
d.context # => {:ignore_whitespace_nodes=>:all, :raw=>:all}
|
||||
|
||||
=== +:respect_whitespace+
|
||||
|
||||
Affects: +REXML::Element.new+, +REXML::Element.text=+.
|
||||
|
||||
By default, all parsed whitespace is respected (that is, stored whitespace not compressed):
|
||||
|
||||
xml_string = '<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.to_s # => "<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>"
|
||||
|
||||
Use +:respect_whitespace+ with an array of element names
|
||||
to specify the elements that _are_ to have their whitespace respected;
|
||||
other elements' whitespace, and whitespace between elements, will be compressed.
|
||||
|
||||
In this example: +foo+ and +baz+ will have their whitespace respected;
|
||||
+bar+ and the space between elements will have their whitespace compressed:
|
||||
|
||||
d = REXML::Document.new(xml_string, {respect_whitespace: ['foo', 'baz']})
|
||||
d.to_s # => "<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>"
|
||||
bar = d.root[2] # => <bar> ... </>
|
||||
bar.text = 'X Y'
|
||||
d.to_s # => "<root><foo>a b</foo> <bar>X Y</bar> <baz>e f</baz></root>"
|
||||
|
||||
=== +:compress_whitespace+
|
||||
|
||||
Affects: +REXML::Element.new+, +REXML::Element.text=+.
|
||||
|
||||
Use <tt>compress_whitespace: :all</tt>
|
||||
to compress whitespace both within and between elements:
|
||||
|
||||
xml_string = '<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>'
|
||||
d = REXML::Document.new(xml_string, {compress_whitespace: :all})
|
||||
d.to_s # => "<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>"
|
||||
|
||||
Use +:compress_whitespace+ with an array of element names
|
||||
to compress whitespace in those elements,
|
||||
but not in other elements nor between elements.
|
||||
|
||||
In this example, +foo+ and +baz+ will have their whitespace compressed;
|
||||
+bar+ and the space between elements will not:
|
||||
|
||||
d = REXML::Document.new(xml_string, {compress_whitespace: ['foo', 'baz']})
|
||||
d.to_s # => "<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>"
|
||||
foo = d.root[0] # => <foo> ... </>
|
||||
foo.text= 'X Y'
|
||||
d.to_s # => "<root><foo>X Y</foo> <bar>c d</bar> <baz>e f</baz></root>"
|
||||
|
||||
=== +:ignore_whitespace_nodes+
|
||||
|
||||
Affects: +REXML::Element.new+.
|
||||
|
||||
Use <tt>ignore_whitespace_nodes: :all</tt> to omit all whitespace-only elements.
|
||||
|
||||
In this example, +bar+ has a text node, while nodes +foo+ and +baz+ do not:
|
||||
|
||||
xml_string = '<root><foo> </foo><bar> BAR </bar><baz> </baz></root>'
|
||||
d = REXML::Document.new(xml_string, {ignore_whitespace_nodes: :all})
|
||||
d.to_s # => "<root><foo> FOO </foo><bar/><baz> BAZ </baz></root>"
|
||||
root = d.root # => <root> ... </>
|
||||
foo = root[0] # => <foo/>
|
||||
bar = root[1] # => <bar> ... </>
|
||||
baz = root[2] # => <baz/>
|
||||
foo.first.class # => NilClass
|
||||
bar.first.class # => REXML::Text
|
||||
baz.first.class # => NilClass
|
||||
|
||||
Use +:ignore_whitespace_nodes+ with an array of element names
|
||||
to specify the elements that are to have whitespace nodes ignored.
|
||||
|
||||
In this example, +bar+ and +baz+ have text nodes, while node +foo+ does not.
|
||||
|
||||
xml_string = '<root><foo> </foo><bar> BAR </bar><baz> </baz></root>'
|
||||
d = REXML::Document.new(xml_string, {ignore_whitespace_nodes: ['foo']})
|
||||
d.to_s # => "<root><foo/><bar> BAR </bar><baz> </baz></root>"
|
||||
root = d.root # => <root> ... </>
|
||||
foo = root[0] # => <foo/>
|
||||
bar = root[1] # => <bar> ... </>
|
||||
baz = root[2] # => <baz> ... </>
|
||||
foo.first.class # => NilClass
|
||||
bar.first.class # => REXML::Text
|
||||
baz.first.class # => REXML::Text
|
||||
|
||||
=== +:raw+
|
||||
|
||||
Affects: +Element.text=+, +Element.add_text+, +Text.to_s+.
|
||||
|
||||
Parsing of +a+ elements is not affected by +raw+:
|
||||
|
||||
xml_string = '<root><a>0 < 1</a><b>1 > 0</b></root>'
|
||||
d = REXML::Document.new(xml_string, {:raw => ['a']})
|
||||
d.root.to_s # => "<root><a>0 < 1</a><b>1 > 0</b></root>"
|
||||
a, b = *d.root.elements
|
||||
a.to_s # => "<a>0 < 1</a>"
|
||||
b.to_s # => "<b>1 > 0</b>"
|
||||
|
||||
But Element#text= is affected:
|
||||
|
||||
a.text = '0 < 1'
|
||||
b.text = '1 > 0'
|
||||
a.to_s # => "<a>0 < 1</a>"
|
||||
b.to_s # => "<b>1 &gt; 0</b>"
|
||||
|
||||
As is Element.add_text:
|
||||
|
||||
a.add_text(' so 1 > 0')
|
||||
b.add_text(' so 0 < 1')
|
||||
a.to_s # => "<a>0 < 1 so 1 > 0</a>"
|
||||
b.to_s # => "<b>1 &gt; 0 so 0 &lt; 1</b>"
|
||||
@@ -0,0 +1,87 @@
|
||||
== Class Child
|
||||
|
||||
Class Child includes module Node;
|
||||
see {Tasks for Node}[node_rdoc.html].
|
||||
|
||||
:include: ../tocs/child_toc.rdoc
|
||||
|
||||
=== Relationships
|
||||
|
||||
==== Task: Set the Parent
|
||||
|
||||
Use method {Child#parent=}[../../../../REXML/Parent.html#method-i-parent-3D]
|
||||
to set the parent:
|
||||
|
||||
e0 = REXML::Element.new('foo')
|
||||
e1 = REXML::Element.new('bar')
|
||||
e1.parent # => nil
|
||||
e1.parent = e0
|
||||
e1.parent # => <foo/>
|
||||
|
||||
==== Task: Insert Previous Sibling
|
||||
|
||||
Use method {Child#previous_sibling=}[../../../../REXML/Parent.html#method-i-previous_sibling-3D]
|
||||
to insert a previous sibling:
|
||||
|
||||
xml_string = '<root><a/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.to_a # => [<a/>, <c/>]
|
||||
c = d.root[1] # => <c/>
|
||||
b = REXML::Element.new('b')
|
||||
c.previous_sibling = b
|
||||
d.root.to_a # => [<a/>, <b/>, <c/>]
|
||||
|
||||
==== Task: Insert Next Sibling
|
||||
|
||||
Use method {Child#next_sibling=}[../../../../REXML/Parent.html#method-i-next-sibling-3D]
|
||||
to insert a previous sibling:
|
||||
|
||||
xml_string = '<root><a/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.to_a # => [<a/>, <c/>]
|
||||
a = d.root[0] # => <a/>
|
||||
b = REXML::Element.new('b')
|
||||
a.next_sibling = b
|
||||
d.root.to_a # => [<a/>, <b/>, <c/>]
|
||||
|
||||
=== Removal or Replacement
|
||||
|
||||
==== Task: Remove Child from Parent
|
||||
|
||||
Use method {Child#remove}[../../../../REXML/Parent.html#method-i-remove]
|
||||
to remove a child from its parent; returns the removed child:
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.to_a # => [<a/>, <b/>, <c/>]
|
||||
b = d.root[1] # => <b/>
|
||||
b.remove # => <b/>
|
||||
d.root.to_a # => [<a/>, <c/>]
|
||||
|
||||
==== Task: Replace Child
|
||||
|
||||
Use method {Child#replace_with}[../../../../REXML/Parent.html#method-i-replace]
|
||||
to replace a child;
|
||||
returns the replaced child:
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.to_a # => [<a/>, <b/>, <c/>]
|
||||
b = d.root[1] # => <b/>
|
||||
d = REXML::Element.new('d')
|
||||
b.replace_with(d) # => <b/>
|
||||
d.root.to_a # => [<a/>, <d/>, <c/>]
|
||||
|
||||
=== Document
|
||||
|
||||
==== Task: Get the Document
|
||||
|
||||
Use method {Child#document}[../../../../REXML/Parent.html#method-i-document]
|
||||
to get the document for the child:
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.to_a # => [<a/>, <b/>, <c/>]
|
||||
b = d.root[1] # => <b/>
|
||||
b.document == d # => true
|
||||
REXML::Child.new.document # => nil
|
||||
@@ -0,0 +1,276 @@
|
||||
== Class Document
|
||||
|
||||
Class Document has methods from its superclasses and included modules;
|
||||
see:
|
||||
|
||||
- {Tasks for Element}[element_rdoc.html].
|
||||
- {Tasks for Parent}[parent_rdoc.html].
|
||||
- {Tasks for Child}[child_rdoc.html].
|
||||
- {Tasks for Node}[node_rdoc.html].
|
||||
- {Module Enumerable}[https://docs.ruby-lang.org/en/master/Enumerable.html].
|
||||
|
||||
:include: ../tocs/document_toc.rdoc
|
||||
|
||||
=== New Document
|
||||
|
||||
==== Task: Create an Empty Document
|
||||
|
||||
Use method {Document::new}[../../../../REXML/Document.html#method-c-new]
|
||||
to create an empty document.
|
||||
|
||||
d = REXML::Document.new
|
||||
|
||||
==== Task: Parse a \String into a New Document
|
||||
|
||||
Use method {Document::new}[../../../../REXML/Document.html#method-c-new]
|
||||
to parse an XML string into a new document:
|
||||
|
||||
xml_string = '<root><a/>text<b/>more<c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root # => <root> ... </>
|
||||
|
||||
==== Task: Parse an \IO Stream into a New Document
|
||||
|
||||
Use method {Document::new}[../../../../REXML/Document.html#method-c-new]
|
||||
to parse an XML \IO stream into a new document:
|
||||
|
||||
xml_string = '<root><a/>text<b/>more<c/></root>'
|
||||
File.write('t.xml', xml_string)
|
||||
d = File.open('t.xml', 'r') do |file|
|
||||
REXML::Document.new(file)
|
||||
end
|
||||
d.root # => <root> ... </>
|
||||
|
||||
==== Task: Create a Document from an Existing Document
|
||||
|
||||
Use method {Document::new}[../../../../REXML/Document.html#method-c-new]
|
||||
to create a document from an existing document.
|
||||
The context and attributes are copied to the new document,
|
||||
but not the children:
|
||||
|
||||
xml_string = '<root><a/>text<b/>more<c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.children # => [<root> ... </>]
|
||||
d.context = {raw: :all, compress_whitespace: :all}
|
||||
d.add_attributes({'bar' => 0, 'baz' => 1})
|
||||
d1 = REXML::Document.new(d)
|
||||
d1.context # => {:raw=>:all, :compress_whitespace=>:all}
|
||||
d1.attributes # => {"bar"=>bar='0', "baz"=>baz='1'}
|
||||
d1.children # => []
|
||||
|
||||
==== Task: Clone a Document
|
||||
|
||||
Use method {Document#clone}[../../../../REXML/Document.html#method-i-clone]
|
||||
to clone a document.
|
||||
The context and attributes are copied to the new document,
|
||||
but not the children:
|
||||
|
||||
xml_string = '<root><a/>text<b/>more<c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.children # => [<root> ... </>]
|
||||
d.context = {raw: :all, compress_whitespace: :all}
|
||||
d.add_attributes({'bar' => 0, 'baz' => 1})
|
||||
d1 = d.clone # => < bar='0' baz='1'/>
|
||||
d1.context # => {:raw=>:all, :compress_whitespace=>:all}
|
||||
d1.attributes # => {"bar"=>bar='0', "baz"=>baz='1'}
|
||||
d1.children # => []
|
||||
|
||||
=== Document Type
|
||||
|
||||
==== Task: Get the Document Type
|
||||
|
||||
Use method {Document#doctype}[../../../../REXML/Document.html#method-i-doctype]
|
||||
to get the document type:
|
||||
|
||||
d = REXML::Document.new('<!DOCTYPE document SYSTEM "subjects.dtd">')
|
||||
d.doctype.class # => REXML::DocType
|
||||
d = REXML::Document.new('')
|
||||
d.doctype.class # => nil
|
||||
|
||||
==== Task: Set the Document Type
|
||||
|
||||
Use method {document#add}[../../../../REXML/Document.html#method-i-add]
|
||||
to add or replace the document type:
|
||||
|
||||
d = REXML::Document.new('')
|
||||
d.doctype.class # => nil
|
||||
d.add(REXML::DocType.new('foo'))
|
||||
d.doctype.class # => REXML::DocType
|
||||
|
||||
=== XML Declaration
|
||||
|
||||
==== Task: Get the XML Declaration
|
||||
|
||||
Use method {document#xml_decl}[../../../../REXML/Document.html#method-i-xml_decl]
|
||||
to get the XML declaration:
|
||||
|
||||
d = REXML::Document.new('<!DOCTYPE document SYSTEM "subjects.dtd">')
|
||||
d.xml_decl.class # => REXML::XMLDecl
|
||||
d.xml_decl # => <?xml ... ?>
|
||||
d = REXML::Document.new('')
|
||||
d.xml_decl.class # => REXML::XMLDecl
|
||||
d.xml_decl # => <?xml ... ?>
|
||||
|
||||
==== Task: Set the XML Declaration
|
||||
|
||||
Use method {document#add}[../../../../REXML/Document.html#method-i-add]
|
||||
to replace the XML declaration:
|
||||
|
||||
d = REXML::Document.new('<!DOCTYPE document SYSTEM "subjects.dtd">')
|
||||
d.add(REXML::XMLDecl.new)
|
||||
|
||||
=== Children
|
||||
|
||||
==== Task: Add an Element Child
|
||||
|
||||
Use method
|
||||
{document#add_element}[../../../../REXML/Document.html#method-i-add_element]
|
||||
to add an element to the document:
|
||||
|
||||
d = REXML::Document.new('')
|
||||
d.add_element(REXML::Element.new('root'))
|
||||
d.children # => [<root/>]
|
||||
|
||||
==== Task: Add a Non-Element Child
|
||||
|
||||
Use method
|
||||
{document#add}[../../../../REXML/Document.html#method-i-add]
|
||||
to add a non-element to the document:
|
||||
|
||||
xml_string = '<root><a/>text<b/>more<c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.add(REXML::Text.new('foo'))
|
||||
d.children # => [<root> ... </>, "foo"]
|
||||
|
||||
=== Writing
|
||||
|
||||
==== Task: Write to $stdout
|
||||
|
||||
Use method
|
||||
{document#write}[../../../../REXML/Document.html#method-i-write]
|
||||
to write the document to <tt>$stdout</tt>:
|
||||
|
||||
xml_string = '<root><a/>text<b/>more<c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.write
|
||||
|
||||
Output:
|
||||
|
||||
<root><a/>text<b/>more<c/></root>
|
||||
|
||||
==== Task: Write to IO Stream
|
||||
|
||||
Use method
|
||||
{document#write}[../../../../REXML/Document.html#method-i-write]
|
||||
to write the document to <tt>$stdout</tt>:
|
||||
|
||||
xml_string = '<root><a/>text<b/>more<c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
File.open('t.xml', 'w') do |file|
|
||||
d.write(file)
|
||||
end
|
||||
p File.read('t.xml')
|
||||
|
||||
Output:
|
||||
|
||||
"<root><a/>text<b/>more<c/></root>"
|
||||
|
||||
==== Task: Write with No Indentation
|
||||
|
||||
Use method
|
||||
{document#write}[../../../../REXML/Document.html#method-i-write]
|
||||
to write the document with no indentation:
|
||||
|
||||
xml_string = '<root><a><b><c></c></b></a></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.write({indent: 0})
|
||||
|
||||
Output:
|
||||
|
||||
<root>
|
||||
<a>
|
||||
<b>
|
||||
<c/>
|
||||
</b>
|
||||
</a>
|
||||
</root>
|
||||
|
||||
==== Task: Write with Specified Indentation
|
||||
|
||||
Use method
|
||||
{document#write}[../../../../REXML/Document.html#method-i-write]
|
||||
to write the document with a specified indentation:
|
||||
|
||||
xml_string = '<root><a><b><c></c></b></a></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.write({indent: 2})
|
||||
|
||||
Output:
|
||||
|
||||
<root>
|
||||
<a>
|
||||
<b>
|
||||
<c/>
|
||||
</b>
|
||||
</a>
|
||||
</root>
|
||||
|
||||
=== Querying
|
||||
|
||||
==== Task: Get the Document
|
||||
|
||||
Use method
|
||||
{document#document}[../../../../REXML/Document.html#method-i-document]
|
||||
to get the document (+self+); overrides <tt>Element#document</tt>:
|
||||
|
||||
xml_string = '<root><a><b><c></c></b></a></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.document == d # => true
|
||||
|
||||
==== Task: Get the Encoding
|
||||
|
||||
Use method
|
||||
{document#document}[../../../../REXML/Document.html#method-i-document]
|
||||
to get the document (+self+); overrides <tt>Element#document</tt>:
|
||||
|
||||
xml_string = '<root><a><b><c></c></b></a></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.encoding # => "UTF-8"
|
||||
|
||||
==== Task: Get the Node Type
|
||||
|
||||
Use method
|
||||
{document#node_type}[../../../../REXML/Document.html#method-i-node_type]
|
||||
to get the node type (+:document+); overrides <tt>Element#node_type</tt>:
|
||||
|
||||
xml_string = '<root><a><b><c></c></b></a></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.node_type # => :document
|
||||
|
||||
==== Task: Get the Root Element
|
||||
|
||||
Use method
|
||||
{document#root}[../../../../REXML/Document.html#method-i-root]
|
||||
to get the root element:
|
||||
|
||||
xml_string = '<root><a><b><c></c></b></a></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root # => <root> ... </>
|
||||
|
||||
==== Task: Determine Whether Stand-Alone
|
||||
|
||||
Use method
|
||||
{document#stand_alone?}[../../../../REXML/Document.html#method-i-stand_alone-3F]
|
||||
to get the stand-alone value:
|
||||
|
||||
d = REXML::Document.new('<?xml standalone="yes"?>')
|
||||
d.stand_alone? # => "yes"
|
||||
|
||||
==== Task: Get the Version
|
||||
|
||||
Use method
|
||||
{document#version}[../../../../REXML/Document.html#method-i-version]
|
||||
to get the version:
|
||||
|
||||
d = REXML::Document.new('<?xml version="2.0" encoding="UTF-8"?>')
|
||||
d.version # => "2.0"
|
||||
@@ -0,0 +1,602 @@
|
||||
== Class Element
|
||||
|
||||
Class Element has methods from its superclasses and included modules;
|
||||
see:
|
||||
|
||||
- {Tasks for Parent}[parent_rdoc.html].
|
||||
- {Tasks for Child}[child_rdoc.html].
|
||||
- {Tasks for Node}[node_rdoc.html].
|
||||
- {Module Enumerable}[https://docs.ruby-lang.org/en/master/Enumerable.html].
|
||||
|
||||
:include: ../tocs/element_toc.rdoc
|
||||
|
||||
=== New Element
|
||||
|
||||
==== Task: Create a Default Element
|
||||
|
||||
Use method
|
||||
{Element::new}[../../../../REXML/Element.html#method-c-new]
|
||||
with no arguments to create a default element:
|
||||
|
||||
e = REXML::Element.new
|
||||
e.name # => "UNDEFINED"
|
||||
e.parent # => nil
|
||||
e.context # => nil
|
||||
|
||||
==== Task: Create a Named Element
|
||||
|
||||
Use method
|
||||
{Element::new}[../../../../REXML/Element.html#method-c-new]
|
||||
with a string name argument
|
||||
to create a named element:
|
||||
|
||||
e = REXML::Element.new('foo')
|
||||
e.name # => "foo"
|
||||
e.parent # => nil
|
||||
e.context # => nil
|
||||
|
||||
==== Task: Create an Element with Name and Parent
|
||||
|
||||
Use method
|
||||
{Element::new}[../../../../REXML/Element.html#method-c-new]
|
||||
with name and parent arguments
|
||||
to create an element with name and parent:
|
||||
|
||||
p = REXML::Parent.new
|
||||
e = REXML::Element.new('foo', p)
|
||||
e.name # => "foo"
|
||||
e.parent # => #<REXML::Parent @parent=nil, @children=[<foo/>]>
|
||||
e.context # => nil
|
||||
|
||||
==== Task: Create an Element with Name, Parent, and Context
|
||||
|
||||
Use method
|
||||
{Element::new}[../../../../REXML/Element.html#method-c-new]
|
||||
with name, parent, and context arguments
|
||||
to create an element with name, parent, and context:
|
||||
|
||||
p = REXML::Parent.new
|
||||
e = REXML::Element.new('foo', p, {compress_whitespace: :all})
|
||||
e.name # => "foo"
|
||||
e.parent # => #<REXML::Parent @parent=nil, @children=[<foo/>]>
|
||||
e.context # => {:compress_whitespace=>:all}
|
||||
|
||||
==== Task: Create a Shallow Clone
|
||||
|
||||
Use method
|
||||
{Element#clone}[../../../../REXML/Element.html#method-i-clone]
|
||||
to create a shallow clone of an element,
|
||||
copying only the name, attributes, and context:
|
||||
|
||||
e0 = REXML::Element.new('foo', nil, {compress_whitespace: :all})
|
||||
e0.add_attribute(REXML::Attribute.new('bar', 'baz'))
|
||||
e0.context = {compress_whitespace: :all}
|
||||
e1 = e0.clone # => <foo bar='baz'/>
|
||||
e1.name # => "foo"
|
||||
e1.context # => {:compress_whitespace=>:all}
|
||||
|
||||
=== Attributes
|
||||
|
||||
==== Task: Create and Add an Attribute
|
||||
|
||||
Use method
|
||||
{Element#add_attribute}[../../../../REXML/Element.html#method-i-add_attribute]
|
||||
to create and add an attribute:
|
||||
|
||||
e = REXML::Element.new
|
||||
e.add_attribute('attr', 'value') # => "value"
|
||||
e['attr'] # => "value"
|
||||
e.add_attribute('attr', 'VALUE') # => "VALUE"
|
||||
e['attr'] # => "VALUE"
|
||||
|
||||
==== Task: Add an Existing Attribute
|
||||
|
||||
Use method
|
||||
{Element#add_attribute}[../../../../REXML/Element.html#method-i-add_attribute]
|
||||
to add an existing attribute:
|
||||
|
||||
e = REXML::Element.new
|
||||
a = REXML::Attribute.new('attr', 'value')
|
||||
e.add_attribute(a)
|
||||
e['attr'] # => "value"
|
||||
a = REXML::Attribute.new('attr', 'VALUE')
|
||||
e.add_attribute(a)
|
||||
e['attr'] # => "VALUE"
|
||||
|
||||
==== Task: Add Multiple Attributes from a Hash
|
||||
|
||||
Use method
|
||||
{Element#add_attributes}[../../../../REXML/Element.html#method-i-add_attributes]
|
||||
to add multiple attributes from a hash:
|
||||
|
||||
e = REXML::Element.new
|
||||
h = {'foo' => 0, 'bar' => 1}
|
||||
e.add_attributes(h)
|
||||
e['foo'] # => "0"
|
||||
e['bar'] # => "1"
|
||||
|
||||
==== Task: Add Multiple Attributes from an Array
|
||||
|
||||
Use method
|
||||
{Element#add_attributes}[../../../../REXML/Element.html#method-i-add_attributes]
|
||||
to add multiple attributes from an array:
|
||||
|
||||
e = REXML::Element.new
|
||||
a = [['foo', 0], ['bar', 1]]
|
||||
e.add_attributes(a)
|
||||
e['foo'] # => "0"
|
||||
e['bar'] # => "1"
|
||||
|
||||
==== Task: Retrieve the Value for an Attribute Name
|
||||
|
||||
Use method
|
||||
{Element#[]}[../../../../REXML/Element.html#method-i-5B-5D]
|
||||
to retrieve the value for an attribute name:
|
||||
|
||||
e = REXML::Element.new
|
||||
e.add_attribute('attr', 'value') # => "value"
|
||||
e['attr'] # => "value"
|
||||
|
||||
==== Task: Retrieve the Attribute Value for a Name and Namespace
|
||||
|
||||
Use method
|
||||
{Element#attribute}[../../../../REXML/Element.html#method-i-attribute]
|
||||
to retrieve the value for an attribute name:
|
||||
|
||||
xml_string = "<root xmlns:a='a' a:x='a:x' x='x'/>"
|
||||
d = REXML::Document.new(xml_string)
|
||||
e = d.root
|
||||
e.attribute("x") # => x='x'
|
||||
e.attribute("x", "a") # => a:x='a:x'
|
||||
|
||||
==== Task: Delete an Attribute
|
||||
|
||||
Use method
|
||||
{Element#delete_attribute}[../../../../REXML/Element.html#method-i-delete_attribute]
|
||||
to remove an attribute:
|
||||
|
||||
e = REXML::Element.new('foo')
|
||||
e.add_attribute('bar', 'baz')
|
||||
e.delete_attribute('bar')
|
||||
e.delete_attribute('bar')
|
||||
e['bar'] # => nil
|
||||
|
||||
==== Task: Determine Whether the Element Has Attributes
|
||||
|
||||
Use method
|
||||
{Element#has_attributes?}[../../../../REXML/Element.html#method-i-has_attributes-3F]
|
||||
to determine whether the element has attributes:
|
||||
|
||||
e = REXML::Element.new('foo')
|
||||
e.has_attributes? # => false
|
||||
e.add_attribute('bar', 'baz')
|
||||
e.has_attributes? # => true
|
||||
|
||||
=== Children
|
||||
|
||||
<em>Element Children</em>
|
||||
|
||||
==== Task: Create and Add an Element
|
||||
|
||||
Use method
|
||||
{Element#add_element}[../../../../REXML/Element.html#method-i-add_element]
|
||||
to create a new element and add it to this element:
|
||||
|
||||
e0 = REXML::Element.new('foo')
|
||||
e0.add_element('bar')
|
||||
e0.children # => [<bar/>]
|
||||
|
||||
==== Task: Add an Existing Element
|
||||
|
||||
Use method
|
||||
{Element#add_element}[../../../../REXML/Element.html#method-i-add_element]
|
||||
to add an element to this element:
|
||||
|
||||
e0 = REXML::Element.new('foo')
|
||||
e1 = REXML::Element.new('bar')
|
||||
e0.add_element(e1)
|
||||
e0.children # => [<bar/>]
|
||||
|
||||
==== Task: Create and Add an Element with Attributes
|
||||
|
||||
Use method
|
||||
{Element#add_element}[../../../../REXML/Element.html#method-i-add_element]
|
||||
to create a new element with attributes, and add it to this element:
|
||||
|
||||
e0 = REXML::Element.new('foo')
|
||||
e0.add_element('bar', {'name' => 'value'})
|
||||
e0.children # => [<bar name='value'/>]
|
||||
|
||||
==== Task: Add an Existing Element with Added Attributes
|
||||
|
||||
Use method
|
||||
{Element#add_element}[../../../../REXML/Element.html#method-i-add_element]
|
||||
to add an element to this element:
|
||||
|
||||
e0 = REXML::Element.new('foo')
|
||||
e1 = REXML::Element.new('bar')
|
||||
e0.add_element(e1, {'name' => 'value'})
|
||||
e0.children # => [<bar name='value'/>]
|
||||
|
||||
==== Task: Delete a Specified Element
|
||||
|
||||
Use method
|
||||
{Element#delete_element}[../../../../REXML/Element.html#method-i-delete_element]
|
||||
to remove a specified element from this element:
|
||||
|
||||
e0 = REXML::Element.new('foo')
|
||||
e1 = REXML::Element.new('bar')
|
||||
e0.add_element(e1)
|
||||
e0.children # => [<bar/>]
|
||||
e0.delete_element(e1)
|
||||
e0.children # => []
|
||||
|
||||
==== Task: Delete an Element by Index
|
||||
|
||||
Use method
|
||||
{Element#delete_element}[../../../../REXML/Element.html#method-i-delete_element]
|
||||
to remove an element from this element by index:
|
||||
|
||||
e0 = REXML::Element.new('foo')
|
||||
e1 = REXML::Element.new('bar')
|
||||
e0.add_element(e1)
|
||||
e0.children # => [<bar/>]
|
||||
e0.delete_element(1)
|
||||
e0.children # => []
|
||||
|
||||
==== Task: Delete an Element by XPath
|
||||
|
||||
Use method
|
||||
{Element#delete_element}[../../../../REXML/Element.html#method-i-delete_element]
|
||||
to remove an element from this element by XPath:
|
||||
|
||||
e0 = REXML::Element.new('foo')
|
||||
e1 = REXML::Element.new('bar')
|
||||
e0.add_element(e1)
|
||||
e0.children # => [<bar/>]
|
||||
e0.delete_element('//bar/')
|
||||
e0.children # => []
|
||||
|
||||
==== Task: Determine Whether Element Children
|
||||
|
||||
Use method
|
||||
{Element#has_elements?}[../../../../REXML/Element.html#method-i-has_elements-3F]
|
||||
to determine whether the element has element children:
|
||||
|
||||
e0 = REXML::Element.new('foo')
|
||||
e0.has_elements? # => false
|
||||
e0.add_element(REXML::Element.new('bar'))
|
||||
e0.has_elements? # => true
|
||||
|
||||
==== Task: Get Element Descendants by XPath
|
||||
|
||||
Use method
|
||||
{Element#get_elements}[../../../../REXML/Element.html#method-i-get_elements]
|
||||
to fetch all element descendant children by XPath:
|
||||
|
||||
xml_string = <<-EOT
|
||||
<root>
|
||||
<a level='1'>
|
||||
<a level='2'/>
|
||||
</a>
|
||||
</root>
|
||||
EOT
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.get_elements('//a') # => [<a level='1'> ... </>, <a level='2'/>]
|
||||
|
||||
==== Task: Get Next Element Sibling
|
||||
|
||||
Use method
|
||||
{Element#next_element}[../../../../REXML/Element.html#method-i-next_element]
|
||||
to retrieve the next element sibling:
|
||||
|
||||
d = REXML::Document.new '<a><b/>text<c/></a>'
|
||||
d.root.elements['b'].next_element #-> <c/>
|
||||
d.root.elements['c'].next_element #-> nil
|
||||
|
||||
==== Task: Get Previous Element Sibling
|
||||
|
||||
Use method
|
||||
{Element#previous_element}[../../../../REXML/Element.html#method-i-previous_element]
|
||||
to retrieve the previous element sibling:
|
||||
|
||||
d = REXML::Document.new '<a><b/>text<c/></a>'
|
||||
d.root.elements['c'].previous_element #-> <b/>
|
||||
d.root.elements['b'].previous_element #-> nil
|
||||
|
||||
<em>Text Children</em>
|
||||
|
||||
==== Task: Add a Text Node
|
||||
|
||||
Use method
|
||||
{Element#add_text}[../../../../REXML/Element.html#method-i-add_text]
|
||||
to add a text node to the element:
|
||||
|
||||
d = REXML::Document.new('<a>foo<b/>bar</a>')
|
||||
e = d.root
|
||||
e.add_text(REXML::Text.new('baz'))
|
||||
e.to_a # => ["foo", <b/>, "bar", "baz"]
|
||||
e.add_text(REXML::Text.new('baz'))
|
||||
e.to_a # => ["foo", <b/>, "bar", "baz", "baz"]
|
||||
|
||||
==== Task: Replace the First Text Node
|
||||
|
||||
Use method
|
||||
{Element#text=}[../../../../REXML/Element.html#method-i-text-3D]
|
||||
to replace the first text node in the element:
|
||||
|
||||
d = REXML::Document.new('<root><a/>text<b/>more<c/></root>')
|
||||
e = d.root
|
||||
e.to_a # => [<a/>, "text", <b/>, "more", <c/>]
|
||||
e.text = 'oops'
|
||||
e.to_a # => [<a/>, "oops", <b/>, "more", <c/>]
|
||||
|
||||
==== Task: Remove the First Text Node
|
||||
|
||||
Use method
|
||||
{Element#text=}[../../../../REXML/Element.html#method-i-text-3D]
|
||||
to remove the first text node in the element:
|
||||
|
||||
d = REXML::Document.new('<root><a/>text<b/>more<c/></root>')
|
||||
e = d.root
|
||||
e.to_a # => [<a/>, "text", <b/>, "more", <c/>]
|
||||
e.text = nil
|
||||
e.to_a # => [<a/>, <b/>, "more", <c/>]
|
||||
|
||||
==== Task: Retrieve the First Text Node
|
||||
|
||||
Use method
|
||||
{Element#get_text}[../../../../REXML/Element.html#method-i-get_text]
|
||||
to retrieve the first text node in the element:
|
||||
|
||||
d = REXML::Document.new('<root><a/>text<b/>more<c/></root>')
|
||||
e = d.root
|
||||
e.to_a # => [<a/>, "text", <b/>, "more", <c/>]
|
||||
e.get_text # => "text"
|
||||
|
||||
==== Task: Retrieve a Specific Text Node
|
||||
|
||||
Use method
|
||||
{Element#get_text}[../../../../REXML/Element.html#method-i-get_text]
|
||||
to retrieve the first text node in a specified element:
|
||||
|
||||
d = REXML::Document.new "<root>some text <b>this is bold!</b> more text</root>"
|
||||
e = d.root
|
||||
e.get_text('//root') # => "some text "
|
||||
e.get_text('//b') # => "this is bold!"
|
||||
|
||||
==== Task: Determine Whether the Element has Text Nodes
|
||||
|
||||
Use method
|
||||
{Element#has_text?}[../../../../REXML/Element.html#method-i-has_text-3F]
|
||||
to determine whether the element has text:
|
||||
|
||||
e = REXML::Element.new('foo')
|
||||
e.has_text? # => false
|
||||
e.add_text('bar')
|
||||
e.has_text? # => true
|
||||
|
||||
<em>Other Children</em>
|
||||
|
||||
==== Task: Get the Child at a Given Index
|
||||
|
||||
Use method
|
||||
{Element#[]}[../../../../REXML/Element.html#method-i-5B-5D]
|
||||
to retrieve the child at a given index:
|
||||
|
||||
d = REXML::Document.new '><root><a/>text<b/>more<c/></root>'
|
||||
e = d.root
|
||||
e[0] # => <a/>
|
||||
e[1] # => "text"
|
||||
e[2] # => <b/>
|
||||
|
||||
==== Task: Get All CDATA Children
|
||||
|
||||
Use method
|
||||
{Element#cdatas}[../../../../REXML/Element.html#method-i-cdatas]
|
||||
to retrieve all CDATA children:
|
||||
|
||||
xml_string = <<-EOT
|
||||
<root>
|
||||
<![CDATA[foo]]>
|
||||
<![CDATA[bar]]>
|
||||
</root>
|
||||
EOT
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.cdatas # => ["foo", "bar"]
|
||||
|
||||
==== Task: Get All Comment Children
|
||||
|
||||
Use method
|
||||
{Element#comments}[../../../../REXML/Element.html#method-i-comments]
|
||||
to retrieve all comment children:
|
||||
|
||||
xml_string = <<-EOT
|
||||
<root>
|
||||
<!--foo-->
|
||||
<!--bar-->
|
||||
</root>
|
||||
EOT
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.comments.map {|comment| comment.to_s } # => ["foo", "bar"]
|
||||
|
||||
==== Task: Get All Processing Instruction Children
|
||||
|
||||
Use method
|
||||
{Element#instructions}[../../../../REXML/Element.html#method-i-instructions]
|
||||
to retrieve all processing instruction children:
|
||||
|
||||
xml_string = <<-EOT
|
||||
<root>
|
||||
<?target0 foo?>
|
||||
<?target1 bar?>
|
||||
</root>
|
||||
EOT
|
||||
d = REXML::Document.new(xml_string)
|
||||
instructions = d.root.instructions.map {|instruction| instruction.to_s }
|
||||
instructions # => ["<?target0 foo?>", "<?target1 bar?>"]
|
||||
|
||||
==== Task: Get All Text Children
|
||||
|
||||
Use method
|
||||
{Element#texts}[../../../../REXML/Element.html#method-i-texts]
|
||||
to retrieve all text children:
|
||||
|
||||
xml_string = '<root><a/>text<b/>more<c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.texts # => ["text", "more"]
|
||||
|
||||
=== Namespaces
|
||||
|
||||
==== Task: Add a Namespace
|
||||
|
||||
Use method
|
||||
{Element#add_namespace}[../../../../REXML/Element.html#method-i-add_namespace]
|
||||
to add a namespace to the element:
|
||||
|
||||
e = REXML::Element.new('foo')
|
||||
e.add_namespace('bar')
|
||||
e.namespaces # => {"xmlns"=>"bar"}
|
||||
|
||||
==== Task: Delete the Default Namespace
|
||||
|
||||
Use method
|
||||
{Element#delete_namespace}[../../../../REXML/Element.html#method-i-delete_namespace]
|
||||
to remove the default namespace from the element:
|
||||
|
||||
d = REXML::Document.new "<a xmlns:foo='bar' xmlns='twiddle'/>"
|
||||
d.to_s # => "<a xmlns:foo='bar' xmlns='twiddle'/>"
|
||||
d.root.delete_namespace # => <a xmlns:foo='bar'/>
|
||||
d.to_s # => "<a xmlns:foo='bar'/>"
|
||||
|
||||
==== Task: Delete a Specific Namespace
|
||||
|
||||
Use method
|
||||
{Element#delete_namespace}[../../../../REXML/Element.html#method-i-delete_namespace]
|
||||
to remove a specific namespace from the element:
|
||||
|
||||
d = REXML::Document.new "<a xmlns:foo='bar' xmlns='twiddle'/>"
|
||||
d.to_s # => "<a xmlns:foo='bar' xmlns='twiddle'/>"
|
||||
d.root.delete_namespace # => <a xmlns:foo='bar'/>
|
||||
d.to_s # => "<a xmlns:foo='bar'/>"
|
||||
d.root.delete_namespace('foo')
|
||||
d.to_s # => "<a/>"
|
||||
|
||||
==== Task: Get a Namespace URI
|
||||
|
||||
Use method
|
||||
{Element#namespace}[../../../../REXML/Element.html#method-i-namespace]
|
||||
to retrieve a specific namespace URI for the element:
|
||||
|
||||
xml_string = <<-EOT
|
||||
<root>
|
||||
<a xmlns='1' xmlns:y='2'>
|
||||
<b/>
|
||||
<c xmlns:z='3'/>
|
||||
</a>
|
||||
</root>
|
||||
EOT
|
||||
d = REXML::Document.new(xml_string)
|
||||
b = d.elements['//b']
|
||||
b.namespace # => "1"
|
||||
b.namespace('y') # => "2"
|
||||
|
||||
==== Task: Retrieve Namespaces
|
||||
|
||||
Use method
|
||||
{Element#namespaces}[../../../../REXML/Element.html#method-i-namespaces]
|
||||
to retrieve all namespaces for the element:
|
||||
|
||||
xml_string = '<a xmlns="foo" xmlns:x="bar" xmlns:y="twee" z="glorp"/>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.attributes.namespaces # => {"xmlns"=>"foo", "x"=>"bar", "y"=>"twee"}
|
||||
|
||||
==== Task: Retrieve Namespace Prefixes
|
||||
|
||||
Use method
|
||||
{Element#prefixes}[../../../../REXML/Element.html#method-i-prefixes]
|
||||
to retrieve all prefixes (namespace names) for the element:
|
||||
|
||||
xml_string = <<-EOT
|
||||
<root>
|
||||
<a xmlns:x='1' xmlns:y='2'>
|
||||
<b/>
|
||||
<c xmlns:z='3'/>
|
||||
</a>
|
||||
</root>
|
||||
EOT
|
||||
d = REXML::Document.new(xml_string, {compress_whitespace: :all})
|
||||
d.elements['//a'].prefixes # => ["x", "y"]
|
||||
d.elements['//b'].prefixes # => ["x", "y"]
|
||||
d.elements['//c'].prefixes # => ["x", "y", "z"]
|
||||
|
||||
=== Iteration
|
||||
|
||||
==== Task: Iterate Over Elements
|
||||
|
||||
Use method
|
||||
{Element#each_element}[../../../../REXML/Element.html#method-i-each_element]
|
||||
to iterate over element children:
|
||||
|
||||
d = REXML::Document.new '<a><b>b</b><c>b</c><d>d</d><e/></a>'
|
||||
d.root.each_element {|e| p e }
|
||||
|
||||
Output:
|
||||
|
||||
<b> ... </>
|
||||
<c> ... </>
|
||||
<d> ... </>
|
||||
<e/>
|
||||
|
||||
==== Task: Iterate Over Elements Having a Specified Attribute
|
||||
|
||||
Use method
|
||||
{Element#each_element_with_attribute}[../../../../REXML/Element.html#method-i-each_element_with_attribute]
|
||||
to iterate over element children that have a specified attribute:
|
||||
|
||||
d = REXML::Document.new '<a><b id="1"/><c id="2"/><d id="1"/><e/></a>'
|
||||
a = d.root
|
||||
a.each_element_with_attribute('id') {|e| p e }
|
||||
|
||||
Output:
|
||||
|
||||
<b id='1'/>
|
||||
<c id='2'/>
|
||||
<d id='1'/>
|
||||
|
||||
==== Task: Iterate Over Elements Having a Specified Attribute and Value
|
||||
|
||||
Use method
|
||||
{Element#each_element_with_attribute}[../../../../REXML/Element.html#method-i-each_element_with_attribute]
|
||||
to iterate over element children that have a specified attribute and value:
|
||||
|
||||
d = REXML::Document.new '<a><b id="1"/><c id="2"/><d id="1"/><e/></a>'
|
||||
a = d.root
|
||||
a.each_element_with_attribute('id', '1') {|e| p e }
|
||||
|
||||
Output:
|
||||
|
||||
<b id='1'/>
|
||||
<d id='1'/>
|
||||
|
||||
==== Task: Iterate Over Elements Having Specified Text
|
||||
|
||||
Use method
|
||||
{Element#each_element_with_text}[../../../../REXML/Element.html#method-i-each_element_with_text]
|
||||
to iterate over element children that have specified text:
|
||||
|
||||
|
||||
=== Context
|
||||
|
||||
#whitespace
|
||||
#ignore_whitespace_nodes
|
||||
#raw
|
||||
|
||||
=== Other Getters
|
||||
|
||||
#document
|
||||
#root
|
||||
#root_node
|
||||
#node_type
|
||||
#xpath
|
||||
#inspect
|
||||
@@ -0,0 +1,97 @@
|
||||
== Module Node
|
||||
|
||||
:include: ../tocs/node_toc.rdoc
|
||||
|
||||
=== Siblings
|
||||
|
||||
==== Task: Find Previous Sibling
|
||||
|
||||
Use method
|
||||
{Node.previous_sibling_node}[../../../../REXML/Node.html#method-i-previous_sibling]
|
||||
to retrieve the previous sibling:
|
||||
|
||||
d = REXML::Document.new('<root><a/><b/><c/></root>')
|
||||
b = d.root[1] # => <b/>
|
||||
b.previous_sibling_node # => <a/>
|
||||
|
||||
==== Task: Find Next Sibling
|
||||
|
||||
Use method
|
||||
{Node.next_sibling_node}[../../../../REXML/Node.html#method-i-next_sibling]
|
||||
to retrieve the next sibling:
|
||||
|
||||
d = REXML::Document.new('<root><a/><b/><c/></root>')
|
||||
b = d.root[1] # => <b/>
|
||||
b.next_sibling_node # => <c/>
|
||||
|
||||
=== Position
|
||||
|
||||
==== Task: Find Own Index Among Siblings
|
||||
|
||||
Use method
|
||||
{Node.index_in_parent}[../../../../REXML/Node.html#method-i-index_in_parent]
|
||||
to retrieve the 1-based index of this node among its siblings:
|
||||
|
||||
d = REXML::Document.new('<root><a/><b/><c/></root>')
|
||||
b = d.root[1] # => <b/>
|
||||
b.index_in_parent # => 2
|
||||
|
||||
=== Recursive Traversal
|
||||
|
||||
==== Task: Traverse Each Recursively
|
||||
|
||||
Use method
|
||||
{Node.each_recursive}[../../../../REXML/Node.html#method-i-each_recursive]
|
||||
to traverse a tree of nodes recursively:
|
||||
|
||||
xml_string = '<root><a><b><c></c></b><b><c></c></b></a></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.each_recursive {|node| p node }
|
||||
|
||||
Output:
|
||||
|
||||
<a> ... </>
|
||||
<b> ... </>
|
||||
<c/>
|
||||
<b> ... </>
|
||||
<c/>
|
||||
|
||||
=== Recursive Search
|
||||
|
||||
==== Task: Traverse Each Recursively
|
||||
|
||||
Use method
|
||||
{Node.find_first_recursive}[../../../../REXML/Node.html#method-i-find_first_recursive]
|
||||
to search a tree of nodes recursively:
|
||||
|
||||
xml_string = '<root><a><b><c></c></b><b><c></c></b></a></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.find_first_recursive {|node| node.name == 'c' } # => <c/>
|
||||
|
||||
=== Representation
|
||||
|
||||
==== Task: Represent a String
|
||||
|
||||
Use method {Node.to_s}[../../../../REXML/Node.html#method-i-to_s]
|
||||
to represent the node as a string:
|
||||
|
||||
xml_string = '<root><a><b><c></c></b><b><c></c></b></a></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.to_s # => "<root><a><b><c/></b><b><c/></b></a></root>"
|
||||
|
||||
=== Parent?
|
||||
|
||||
==== Task: Determine Whether the Node is a Parent
|
||||
|
||||
Use method {Node.parent?}[../../../../REXML/Node.html#method-i-parent-3F]
|
||||
to determine whether the node is a parent;
|
||||
class Text derives from Node:
|
||||
|
||||
d = REXML::Document.new('<root><a/>text<b/>more<c/></root>')
|
||||
t = d.root[1] # => "text"
|
||||
t.parent? # => false
|
||||
|
||||
Class Parent also derives from Node, but overrides this method:
|
||||
|
||||
p = REXML::Parent.new
|
||||
p.parent? # => true
|
||||
@@ -0,0 +1,267 @@
|
||||
== Class Parent
|
||||
|
||||
Class Parent has methods from its superclasses and included modules;
|
||||
see:
|
||||
|
||||
- {Tasks for Child}[child_rdoc.html].
|
||||
- {Tasks for Node}[node_rdoc.html].
|
||||
- {Module Enumerable}[https://docs.ruby-lang.org/en/master/Enumerable.html].
|
||||
|
||||
:include: ../tocs/parent_toc.rdoc
|
||||
|
||||
=== Queries
|
||||
|
||||
==== Task: Get the Count of Children
|
||||
|
||||
Use method {Parent#size}[../../../../REXML/Parent.html#method-i-size]
|
||||
(or its alias +length+) to get the count of the parent's children:
|
||||
|
||||
p = REXML::Parent.new
|
||||
p.size # => 0
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.size # => 3
|
||||
|
||||
==== Task: Get the Child at a Given Index
|
||||
|
||||
Use method {Parent#[]}[../../../../REXML/Parent.html#method-i-5B-5D]
|
||||
to get the child at a given index:
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root[1] # => <b/>
|
||||
d.root[-1] # => <c/>
|
||||
d.root[50] # => nil
|
||||
|
||||
==== Task: Get the Index of a Given Child
|
||||
|
||||
Use method {Parent#index}[../../../../REXML/Parent.html#method-i-index]
|
||||
to get the index (0-based offset) of a child:
|
||||
|
||||
d = REXML::Document.new('<root></root>')
|
||||
root = d.root
|
||||
e0 = REXML::Element.new('foo')
|
||||
e1 = REXML::Element.new('bar')
|
||||
root.add(e0) # => <foo/>
|
||||
root.add(e1) # => <bar/>
|
||||
root.add(e0) # => <foo/>
|
||||
root.add(e1) # => <bar/>
|
||||
root.index(e0) # => 0
|
||||
root.index(e1) # => 1
|
||||
|
||||
==== Task: Get the Children
|
||||
|
||||
Use method {Parent#children}[../../../../REXML/Parent.html#method-i-children]
|
||||
(or its alias +to_a+) to get the parent's children:
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.children # => [<a/>, <b/>, <c/>]
|
||||
|
||||
==== Task: Determine Whether the Node is a Parent
|
||||
|
||||
Use method {Parent#parent?}[../../../../REXML/Parent.html#method-i-parent-3F]
|
||||
to determine whether the node is a parent;
|
||||
class Text derives from Node:
|
||||
|
||||
d = REXML::Document.new('<root><a/>text<b/>more<c/></root>')
|
||||
t = d.root[1] # => "text"
|
||||
t.parent? # => false
|
||||
|
||||
Class Parent also derives from Node, but overrides this method:
|
||||
|
||||
p = REXML::Parent.new
|
||||
p.parent? # => true
|
||||
|
||||
=== Additions
|
||||
|
||||
==== Task: Add a Child at the Beginning
|
||||
|
||||
Use method {Parent#unshift}[../../../../REXML/Parent.html#method-i-unshift]
|
||||
to add a child as at the beginning of the children:
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.children # => [<a/>, <b/>, <c/>]
|
||||
d.root.unshift REXML::Element.new('d')
|
||||
d.root.children # => [<d/>, <a/>, <b/>, <c/>]
|
||||
|
||||
==== Task: Add a Child at the End
|
||||
|
||||
Use method {Parent#<<}[../../../../REXML/Parent.html#method-i-3C-3C]
|
||||
(or an alias +push+ or +add+) to add a child as at the end of the children:
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.children # => [<a/>, <b/>, <c/>]
|
||||
d.root << REXML::Element.new('d')
|
||||
d.root.children # => [<a/>, <b/>, <c/>, <d/>]
|
||||
|
||||
==== Task: Replace a Child with Another Child
|
||||
|
||||
Use method {Parent#replace}[../../../../REXML/Parent.html#method-i-replace]
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.children # => [<a/>, <b/>, <c/>]
|
||||
b = d.root[1] # => <b/>
|
||||
d.replace_child(b, REXML::Element.new('d'))
|
||||
d.root.children # => [<a/>, <c/>]
|
||||
|
||||
==== Task: Replace Multiple Children with Another Child
|
||||
|
||||
Use method {Parent#[]=}[../../../../REXML/Parent.html#method-i-parent-5B-5D-3D]
|
||||
to replace multiple consecutive children with another child:
|
||||
|
||||
xml_string = '<root><a/><b/><c/><d/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.children # => [<a/>, <b/>, <c/>, <d/>]
|
||||
d.root[1, 2] = REXML::Element.new('x')
|
||||
d.root.children # => [<a/>, <x/>, <d/>]
|
||||
d.root[1, 5] = REXML::Element.new('x')
|
||||
d.root.children # => [<a/>, <x/>] # BUG?
|
||||
|
||||
==== Task: Insert Child Before a Given Child
|
||||
|
||||
Use method {Parent#insert_before}[../../../../REXML/Parent.html#method-i-insert_before]
|
||||
to insert a child immediately before a given child:
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.children # => [<a/>, <b/>, <c/>]
|
||||
b = d.root[1] # => <b/>
|
||||
x = REXML::Element.new('x')
|
||||
d.root.insert_before(b, x)
|
||||
d.root.children # => [<a/>, <x/>, <b/>, <c/>]
|
||||
|
||||
==== Task: Insert Child After a Given Child
|
||||
|
||||
Use method {Parent#insert_after}[../../../../REXML/Parent.html#method-i-insert_after]
|
||||
to insert a child immediately after a given child:
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.children # => [<a/>, <b/>, <c/>]
|
||||
b = d.root[1] # => <b/>
|
||||
x = REXML::Element.new('x')
|
||||
d.root.insert_after(b, x)
|
||||
d.root.children # => [<a/>, <b/>, <x/>, <c/>]
|
||||
|
||||
=== Deletions
|
||||
|
||||
==== Task: Remove a Given Child
|
||||
|
||||
Use method {Parent#delete}[../../../../REXML/Parent.html#method-i-delete]
|
||||
to remove all occurrences of a given child:
|
||||
|
||||
d = REXML::Document.new('<root></root>')
|
||||
a = REXML::Element.new('a')
|
||||
b = REXML::Element.new('b')
|
||||
d.root.add(a)
|
||||
d.root.add(b)
|
||||
d.root.add(a)
|
||||
d.root.add(b)
|
||||
d.root.children # => [<a/>, <b/>, <a/>, <b/>]
|
||||
d.root.delete(b)
|
||||
d.root.children # => [<a/>, <a/>]
|
||||
|
||||
==== Task: Remove the Child at a Specified Offset
|
||||
|
||||
Use method {Parent#delete_at}[../../../../REXML/Parent.html#method-i-delete_at]
|
||||
to remove the child at a specified offset:
|
||||
|
||||
d = REXML::Document.new('<root></root>')
|
||||
a = REXML::Element.new('a')
|
||||
b = REXML::Element.new('b')
|
||||
d.root.add(a)
|
||||
d.root.add(b)
|
||||
d.root.add(a)
|
||||
d.root.add(b)
|
||||
d.root.children # => [<a/>, <b/>, <a/>, <b/>]
|
||||
d.root.delete_at(2)
|
||||
d.root.children # => [<a/>, <b/>, <b/>]
|
||||
|
||||
==== Task: Remove Children That Meet Specified Criteria
|
||||
|
||||
Use method {Parent#delete_if}[../../../../REXML/Parent.html#method-i-delete_if]
|
||||
to remove children that meet criteria specified in the given block:
|
||||
|
||||
d = REXML::Document.new('<root></root>')
|
||||
d.root.add(REXML::Element.new('x'))
|
||||
d.root.add(REXML::Element.new('xx'))
|
||||
d.root.add(REXML::Element.new('xxx'))
|
||||
d.root.add(REXML::Element.new('xxxx'))
|
||||
d.root.children # => [<x/>, <xx/>, <xxx/>, <xxxx/>]
|
||||
d.root.delete_if {|child| child.name.size.odd? }
|
||||
d.root.children # => [<xx/>, <xxxx/>]
|
||||
|
||||
=== Iterations
|
||||
|
||||
==== Task: Iterate Over Children
|
||||
|
||||
Use method {Parent#each_child}[../../../../REXML/Parent.html#method-i-each_child]
|
||||
(or its alias +each+) to iterate over all children:
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.children # => [<a/>, <b/>, <c/>]
|
||||
d.root.each_child {|child| p child }
|
||||
|
||||
Output:
|
||||
|
||||
<a/>
|
||||
<b/>
|
||||
<c/>
|
||||
|
||||
==== Task: Iterate Over Child Indexes
|
||||
|
||||
Use method {Parent#each_index}[../../../../REXML/Parent.html#method-i-each_index]
|
||||
to iterate over all child indexes:
|
||||
|
||||
xml_string = '<root><a/><b/><c/></root>'
|
||||
d = REXML::Document.new(xml_string)
|
||||
d.root.children # => [<a/>, <b/>, <c/>]
|
||||
d.root.each_index {|child| p child }
|
||||
|
||||
Output:
|
||||
|
||||
0
|
||||
1
|
||||
2
|
||||
|
||||
=== Clones
|
||||
|
||||
==== Task: Clone Deeply
|
||||
|
||||
Use method {Parent#deep_clone}[../../../../REXML/Parent.html#method-i-deep_clone]
|
||||
to clone deeply; that is, to clone every nested node that is a Parent object:
|
||||
|
||||
xml_string = <<-EOT
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<bookstore>
|
||||
<book category="cooking">
|
||||
<title lang="en">Everyday Italian</title>
|
||||
<author>Giada De Laurentiis</author>
|
||||
<year>2005</year>
|
||||
<price>30.00</price>
|
||||
</book>
|
||||
<book category="children">
|
||||
<title lang="en">Harry Potter</title>
|
||||
<author>J K. Rowling</author>
|
||||
<year>2005</year>
|
||||
<price>29.99</price>
|
||||
</book>
|
||||
<book category="web">
|
||||
<title lang="en">Learning XML</title>
|
||||
<author>Erik T. Ray</author>
|
||||
<year>2003</year>
|
||||
<price>39.95</price>
|
||||
</book>
|
||||
</bookstore>
|
||||
EOT
|
||||
d = REXML::Document.new(xml_string)
|
||||
root = d.root
|
||||
shallow = root.clone
|
||||
deep = root.deep_clone
|
||||
shallow.to_s.size # => 12
|
||||
deep.to_s.size # => 590
|
||||
@@ -0,0 +1,12 @@
|
||||
Tasks on this page:
|
||||
|
||||
- {Relationships}[#label-Relationships]
|
||||
- {Task: Set the Parent}[#label-Task-3A+Set+the+Parent]
|
||||
- {Task: Insert Previous Sibling}[#label-Task-3A+Insert+Previous+Sibling]
|
||||
- {Task: Insert Next Sibling}[#label-Task-3A+Insert+Next+Sibling]
|
||||
- {Removal or Replacement}[#label-Removal+or+Replacement]
|
||||
- {Task: Remove Child from Parent}[#label-Task-3A+Remove+Child+from+Parent]
|
||||
- {Task: Replace Child}[#label-Task-3A+Replace+Child]
|
||||
- {Document}[#label-Document]
|
||||
- {Task: Get the Document}[#label-Task-3A+Get+the+Document]
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
Tasks on this page:
|
||||
|
||||
- {New Document}[#label-New+Document]
|
||||
- {Task: Create an Empty Document}[#label-Task-3A+Create+an+Empty+Document]
|
||||
- {Task: Parse a String into a New Document}[#label-Task-3A+Parse+a+String+into+a+New+Document]
|
||||
- {Task: Parse an IO Stream into a New Document}[#label-Task-3A+Parse+an+IO+Stream+into+a+New+Document]
|
||||
- {Task: Create a Document from an Existing Document}[#label-Task-3A+Create+a+Document+from+an+Existing+Document]
|
||||
- {Task: Clone a Document}[#label-Task-3A+Clone+a+Document]
|
||||
- {Document Type}[#label-Document+Type]
|
||||
- {Task: Get the Document Type}[#label-Task-3A+Get+the+Document+Type]
|
||||
- {Task: Set the Document Type}[#label-Task-3A+Set+the+Document+Type]
|
||||
- {XML Declaration}[#label-XML+Declaration]
|
||||
- {Task: Get the XML Declaration}[#label-Task-3A+Get+the+XML+Declaration]
|
||||
- {Task: Set the XML Declaration}[#label-Task-3A+Set+the+XML+Declaration]
|
||||
- {Children}[#label-Children]
|
||||
- {Task: Add an Element Child}[#label-Task-3A+Add+an+Element+Child]
|
||||
- {Task: Add a Non-Element Child}[#label-Task-3A+Add+a+Non-Element+Child]
|
||||
- {Writing}[#label-Writing]
|
||||
- {Task: Write to $stdout}[#label-Task-3A+Write+to+-24stdout]
|
||||
- {Task: Write to IO Stream}[#label-Task-3A+Write+to+IO+Stream]
|
||||
- {Task: Write with No Indentation}[#label-Task-3A+Write+with+No+Indentation]
|
||||
- {Task: Write with Specified Indentation}[#label-Task-3A+Write+with+Specified+Indentation]
|
||||
- {Querying}[#label-Querying]
|
||||
- {Task: Get the Document}[#label-Task-3A+Get+the+Document]
|
||||
- {Task: Get the Encoding}[#label-Task-3A+Get+the+Encoding]
|
||||
- {Task: Get the Node Type}[#label-Task-3A+Get+the+Node+Type]
|
||||
- {Task: Get the Root Element}[#label-Task-3A+Get+the+Root+Element]
|
||||
- {Task: Determine Whether Stand-Alone}[#label-Task-3A+Determine+Whether+Stand-Alone]
|
||||
- {Task: Get the Version}[#label-Task-3A+Get+the+Version]
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
Tasks on this page:
|
||||
|
||||
- {New Element}[#label-New+Element]
|
||||
- {Task: Create a Default Element}[#label-Task-3A+Create+a+Default+Element]
|
||||
- {Task: Create a Named Element}[#label-Task-3A+Create+a+Named+Element]
|
||||
- {Task: Create an Element with Name and Parent}[#label-Task-3A+Create+an+Element+with+Name+and+Parent]
|
||||
- {Task: Create an Element with Name, Parent, and Context}[#label-Task-3A+Create+an+Element+with+Name-2C+Parent-2C+and+Context]
|
||||
- {Task: Create a Shallow Clone}[#label-Task-3A+Create+a+Shallow+Clone]
|
||||
- {Attributes}[#label-Attributes]
|
||||
- {Task: Create and Add an Attribute}[#label-Task-3A+Create+and+Add+an+Attribute]
|
||||
- {Task: Add an Existing Attribute}[#label-Task-3A+Add+an+Existing+Attribute]
|
||||
- {Task: Add Multiple Attributes from a Hash}[#label-Task-3A+Add+Multiple+Attributes+from+a+Hash]
|
||||
- {Task: Add Multiple Attributes from an Array}[#label-Task-3A+Add+Multiple+Attributes+from+an+Array]
|
||||
- {Task: Retrieve the Value for an Attribute Name}[#label-Task-3A+Retrieve+the+Value+for+an+Attribute+Name]
|
||||
- {Task: Retrieve the Attribute Value for a Name and Namespace}[#label-Task-3A+Retrieve+the+Attribute+Value+for+a+Name+and+Namespace]
|
||||
- {Task: Delete an Attribute}[#label-Task-3A+Delete+an+Attribute]
|
||||
- {Task: Determine Whether the Element Has Attributes}[#label-Task-3A+Determine+Whether+the+Element+Has+Attributes]
|
||||
- {Children}[#label-Children]
|
||||
- {Task: Create and Add an Element}[#label-Task-3A+Create+and+Add+an+Element]
|
||||
- {Task: Add an Existing Element}[#label-Task-3A+Add+an+Existing+Element]
|
||||
- {Task: Create and Add an Element with Attributes}[#label-Task-3A+Create+and+Add+an+Element+with+Attributes]
|
||||
- {Task: Add an Existing Element with Added Attributes}[#label-Task-3A+Add+an+Existing+Element+with+Added+Attributes]
|
||||
- {Task: Delete a Specified Element}[#label-Task-3A+Delete+a+Specified+Element]
|
||||
- {Task: Delete an Element by Index}[#label-Task-3A+Delete+an+Element+by+Index]
|
||||
- {Task: Delete an Element by XPath}[#label-Task-3A+Delete+an+Element+by+XPath]
|
||||
- {Task: Determine Whether Element Children}[#label-Task-3A+Determine+Whether+Element+Children]
|
||||
- {Task: Get Element Descendants by XPath}[#label-Task-3A+Get+Element+Descendants+by+XPath]
|
||||
- {Task: Get Next Element Sibling}[#label-Task-3A+Get+Next+Element+Sibling]
|
||||
- {Task: Get Previous Element Sibling}[#label-Task-3A+Get+Previous+Element+Sibling]
|
||||
- {Task: Add a Text Node}[#label-Task-3A+Add+a+Text+Node]
|
||||
- {Task: Replace the First Text Node}[#label-Task-3A+Replace+the+First+Text+Node]
|
||||
- {Task: Remove the First Text Node}[#label-Task-3A+Remove+the+First+Text+Node]
|
||||
- {Task: Retrieve the First Text Node}[#label-Task-3A+Retrieve+the+First+Text+Node]
|
||||
- {Task: Retrieve a Specific Text Node}[#label-Task-3A+Retrieve+a+Specific+Text+Node]
|
||||
- {Task: Determine Whether the Element has Text Nodes}[#label-Task-3A+Determine+Whether+the+Element+has+Text+Nodes]
|
||||
- {Task: Get the Child at a Given Index}[#label-Task-3A+Get+the+Child+at+a+Given+Index]
|
||||
- {Task: Get All CDATA Children}[#label-Task-3A+Get+All+CDATA+Children]
|
||||
- {Task: Get All Comment Children}[#label-Task-3A+Get+All+Comment+Children]
|
||||
- {Task: Get All Processing Instruction Children}[#label-Task-3A+Get+All+Processing+Instruction+Children]
|
||||
- {Task: Get All Text Children}[#label-Task-3A+Get+All+Text+Children]
|
||||
- {Namespaces}[#label-Namespaces]
|
||||
- {Task: Add a Namespace}[#label-Task-3A+Add+a+Namespace]
|
||||
- {Task: Delete the Default Namespace}[#label-Task-3A+Delete+the+Default+Namespace]
|
||||
- {Task: Delete a Specific Namespace}[#label-Task-3A+Delete+a+Specific+Namespace]
|
||||
- {Task: Get a Namespace URI}[#label-Task-3A+Get+a+Namespace+URI]
|
||||
- {Task: Retrieve Namespaces}[#label-Task-3A+Retrieve+Namespaces]
|
||||
- {Task: Retrieve Namespace Prefixes}[#label-Task-3A+Retrieve+Namespace+Prefixes]
|
||||
- {Iteration}[#label-Iteration]
|
||||
- {Task: Iterate Over Elements}[#label-Task-3A+Iterate+Over+Elements]
|
||||
- {Task: Iterate Over Elements Having a Specified Attribute}[#label-Task-3A+Iterate+Over+Elements+Having+a+Specified+Attribute]
|
||||
- {Task: Iterate Over Elements Having a Specified Attribute and Value}[#label-Task-3A+Iterate+Over+Elements+Having+a+Specified+Attribute+and+Value]
|
||||
- {Task: Iterate Over Elements Having Specified Text}[#label-Task-3A+Iterate+Over+Elements+Having+Specified+Text]
|
||||
- {Context}[#label-Context]
|
||||
- {Other Getters}[#label-Other+Getters]
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
== Tasks
|
||||
|
||||
=== {Child}[../../tasks/rdoc/child_rdoc.html]
|
||||
- {Relationships}[../../tasks/rdoc/child_rdoc.html#label-Relationships]
|
||||
- {Task: Set the Parent}[../../tasks/rdoc/child_rdoc.html#label-Task-3A+Set+the+Parent]
|
||||
- {Task: Insert Previous Sibling}[../../tasks/rdoc/child_rdoc.html#label-Task-3A+Insert+Previous+Sibling]
|
||||
- {Task: Insert Next Sibling}[../../tasks/rdoc/child_rdoc.html#label-Task-3A+Insert+Next+Sibling]
|
||||
- {Removal or Replacement}[../../tasks/rdoc/child_rdoc.html#label-Removal+or+Replacement]
|
||||
- {Task: Remove Child from Parent}[../../tasks/rdoc/child_rdoc.html#label-Task-3A+Remove+Child+from+Parent]
|
||||
- {Task: Replace Child}[../../tasks/rdoc/child_rdoc.html#label-Task-3A+Replace+Child]
|
||||
- {Document}[../../tasks/rdoc/child_rdoc.html#label-Document]
|
||||
- {Task: Get the Document}[../../tasks/rdoc/child_rdoc.html#label-Task-3A+Get+the+Document]
|
||||
|
||||
=== {Document}[../../tasks/rdoc/document_rdoc.html]
|
||||
- {New Document}[../../tasks/rdoc/document_rdoc.html#label-New+Document]
|
||||
- {Task: Create an Empty Document}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Create+an+Empty+Document]
|
||||
- {Task: Parse a String into a New Document}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Parse+a+String+into+a+New+Document]
|
||||
- {Task: Parse an IO Stream into a New Document}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Parse+an+IO+Stream+into+a+New+Document]
|
||||
- {Task: Create a Document from an Existing Document}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Create+a+Document+from+an+Existing+Document]
|
||||
- {Task: Clone a Document}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Clone+a+Document]
|
||||
- {Document Type}[../../tasks/rdoc/document_rdoc.html#label-Document+Type]
|
||||
- {Task: Get the Document Type}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Get+the+Document+Type]
|
||||
- {Task: Set the Document Type}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Set+the+Document+Type]
|
||||
- {XML Declaration}[../../tasks/rdoc/document_rdoc.html#label-XML+Declaration]
|
||||
- {Task: Get the XML Declaration}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Get+the+XML+Declaration]
|
||||
- {Task: Set the XML Declaration}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Set+the+XML+Declaration]
|
||||
- {Children}[../../tasks/rdoc/document_rdoc.html#label-Children]
|
||||
- {Task: Add an Element Child}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Add+an+Element+Child]
|
||||
- {Task: Add a Non-Element Child}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Add+a+Non-Element+Child]
|
||||
- {Writing}[../../tasks/rdoc/document_rdoc.html#label-Writing]
|
||||
- {Task: Write to $stdout}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Write+to+-24stdout]
|
||||
- {Task: Write to IO Stream}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Write+to+IO+Stream]
|
||||
- {Task: Write with No Indentation}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Write+with+No+Indentation]
|
||||
- {Task: Write with Specified Indentation}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Write+with+Specified+Indentation]
|
||||
- {Querying}[../../tasks/rdoc/document_rdoc.html#label-Querying]
|
||||
- {Task: Get the Document}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Get+the+Document]
|
||||
- {Task: Get the Encoding}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Get+the+Encoding]
|
||||
- {Task: Get the Node Type}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Get+the+Node+Type]
|
||||
- {Task: Get the Root Element}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Get+the+Root+Element]
|
||||
- {Task: Determine Whether Stand-Alone}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Determine+Whether+Stand-Alone]
|
||||
- {Task: Get the Version}[../../tasks/rdoc/document_rdoc.html#label-Task-3A+Get+the+Version]
|
||||
|
||||
=== {Element}[../../tasks/rdoc/element_rdoc.html]
|
||||
- {New Element}[../../tasks/rdoc/element_rdoc.html#label-New+Element]
|
||||
- {Task: Create a Default Element}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Create+a+Default+Element]
|
||||
- {Task: Create a Named Element}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Create+a+Named+Element]
|
||||
- {Task: Create an Element with Name and Parent}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Create+an+Element+with+Name+and+Parent]
|
||||
- {Task: Create an Element with Name, Parent, and Context}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Create+an+Element+with+Name-2C+Parent-2C+and+Context]
|
||||
- {Task: Create a Shallow Clone}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Create+a+Shallow+Clone]
|
||||
- {Attributes}[../../tasks/rdoc/element_rdoc.html#label-Attributes]
|
||||
- {Task: Create and Add an Attribute}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Create+and+Add+an+Attribute]
|
||||
- {Task: Add an Existing Attribute}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Add+an+Existing+Attribute]
|
||||
- {Task: Add Multiple Attributes from a Hash}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Add+Multiple+Attributes+from+a+Hash]
|
||||
- {Task: Add Multiple Attributes from an Array}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Add+Multiple+Attributes+from+an+Array]
|
||||
- {Task: Retrieve the Value for an Attribute Name}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Retrieve+the+Value+for+an+Attribute+Name]
|
||||
- {Task: Retrieve the Attribute Value for a Name and Namespace}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Retrieve+the+Attribute+Value+for+a+Name+and+Namespace]
|
||||
- {Task: Delete an Attribute}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Delete+an+Attribute]
|
||||
- {Task: Determine Whether the Element Has Attributes}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Determine+Whether+the+Element+Has+Attributes]
|
||||
- {Children}[../../tasks/rdoc/element_rdoc.html#label-Children]
|
||||
- {Task: Create and Add an Element}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Create+and+Add+an+Element]
|
||||
- {Task: Add an Existing Element}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Add+an+Existing+Element]
|
||||
- {Task: Create and Add an Element with Attributes}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Create+and+Add+an+Element+with+Attributes]
|
||||
- {Task: Add an Existing Element with Added Attributes}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Add+an+Existing+Element+with+Added+Attributes]
|
||||
- {Task: Delete a Specified Element}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Delete+a+Specified+Element]
|
||||
- {Task: Delete an Element by Index}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Delete+an+Element+by+Index]
|
||||
- {Task: Delete an Element by XPath}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Delete+an+Element+by+XPath]
|
||||
- {Task: Determine Whether Element Children}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Determine+Whether+Element+Children]
|
||||
- {Task: Get Element Descendants by XPath}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Get+Element+Descendants+by+XPath]
|
||||
- {Task: Get Next Element Sibling}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Get+Next+Element+Sibling]
|
||||
- {Task: Get Previous Element Sibling}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Get+Previous+Element+Sibling]
|
||||
- {Task: Add a Text Node}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Add+a+Text+Node]
|
||||
- {Task: Replace the First Text Node}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Replace+the+First+Text+Node]
|
||||
- {Task: Remove the First Text Node}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Remove+the+First+Text+Node]
|
||||
- {Task: Retrieve the First Text Node}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Retrieve+the+First+Text+Node]
|
||||
- {Task: Retrieve a Specific Text Node}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Retrieve+a+Specific+Text+Node]
|
||||
- {Task: Determine Whether the Element has Text Nodes}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Determine+Whether+the+Element+has+Text+Nodes]
|
||||
- {Task: Get the Child at a Given Index}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Get+the+Child+at+a+Given+Index]
|
||||
- {Task: Get All CDATA Children}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Get+All+CDATA+Children]
|
||||
- {Task: Get All Comment Children}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Get+All+Comment+Children]
|
||||
- {Task: Get All Processing Instruction Children}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Get+All+Processing+Instruction+Children]
|
||||
- {Task: Get All Text Children}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Get+All+Text+Children]
|
||||
- {Namespaces}[../../tasks/rdoc/element_rdoc.html#label-Namespaces]
|
||||
- {Task: Add a Namespace}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Add+a+Namespace]
|
||||
- {Task: Delete the Default Namespace}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Delete+the+Default+Namespace]
|
||||
- {Task: Delete a Specific Namespace}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Delete+a+Specific+Namespace]
|
||||
- {Task: Get a Namespace URI}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Get+a+Namespace+URI]
|
||||
- {Task: Retrieve Namespaces}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Retrieve+Namespaces]
|
||||
- {Task: Retrieve Namespace Prefixes}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Retrieve+Namespace+Prefixes]
|
||||
- {Iteration}[../../tasks/rdoc/element_rdoc.html#label-Iteration]
|
||||
- {Task: Iterate Over Elements}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Iterate+Over+Elements]
|
||||
- {Task: Iterate Over Elements Having a Specified Attribute}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Iterate+Over+Elements+Having+a+Specified+Attribute]
|
||||
- {Task: Iterate Over Elements Having a Specified Attribute and Value}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Iterate+Over+Elements+Having+a+Specified+Attribute+and+Value]
|
||||
- {Task: Iterate Over Elements Having Specified Text}[../../tasks/rdoc/element_rdoc.html#label-Task-3A+Iterate+Over+Elements+Having+Specified+Text]
|
||||
- {Context}[../../tasks/rdoc/element_rdoc.html#label-Context]
|
||||
- {Other Getters}[../../tasks/rdoc/element_rdoc.html#label-Other+Getters]
|
||||
|
||||
=== {Node}[../../tasks/rdoc/node_rdoc.html]
|
||||
- {Siblings}[../../tasks/rdoc/node_rdoc.html#label-Siblings]
|
||||
- {Task: Find Previous Sibling}[../../tasks/rdoc/node_rdoc.html#label-Task-3A+Find+Previous+Sibling]
|
||||
- {Task: Find Next Sibling}[../../tasks/rdoc/node_rdoc.html#label-Task-3A+Find+Next+Sibling]
|
||||
- {Position}[../../tasks/rdoc/node_rdoc.html#label-Position]
|
||||
- {Task: Find Own Index Among Siblings}[../../tasks/rdoc/node_rdoc.html#label-Task-3A+Find+Own+Index+Among+Siblings]
|
||||
- {Recursive Traversal}[../../tasks/rdoc/node_rdoc.html#label-Recursive+Traversal]
|
||||
- {Task: Traverse Each Recursively}[../../tasks/rdoc/node_rdoc.html#label-Task-3A+Traverse+Each+Recursively]
|
||||
- {Recursive Search}[../../tasks/rdoc/node_rdoc.html#label-Recursive+Search]
|
||||
- {Task: Traverse Each Recursively}[../../tasks/rdoc/node_rdoc.html#label-Task-3A+Traverse+Each+Recursively]
|
||||
- {Representation}[../../tasks/rdoc/node_rdoc.html#label-Representation]
|
||||
- {Task: Represent a String}[../../tasks/rdoc/node_rdoc.html#label-Task-3A+Represent+a+String]
|
||||
- {Parent?}[../../tasks/rdoc/node_rdoc.html#label-Parent-3F]
|
||||
- {Task: Determine Whether the Node is a Parent}[../../tasks/rdoc/node_rdoc.html#label-Task-3A+Determine+Whether+the+Node+is+a+Parent]
|
||||
|
||||
=== {Parent}[../../tasks/rdoc/parent_rdoc.html]
|
||||
- {Queries}[../../tasks/rdoc/parent_rdoc.html#label-Queries]
|
||||
- {Task: Get the Count of Children}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Get+the+Count+of+Children]
|
||||
- {Task: Get the Child at a Given Index}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Get+the+Child+at+a+Given+Index]
|
||||
- {Task: Get the Index of a Given Child}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Get+the+Index+of+a+Given+Child]
|
||||
- {Task: Get the Children}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Get+the+Children]
|
||||
- {Task: Determine Whether the Node is a Parent}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Determine+Whether+the+Node+is+a+Parent]
|
||||
- {Additions}[../../tasks/rdoc/parent_rdoc.html#label-Additions]
|
||||
- {Task: Add a Child at the Beginning}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Add+a+Child+at+the+Beginning]
|
||||
- {Task: Add a Child at the End}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Add+a+Child+at+the+End]
|
||||
- {Task: Replace a Child with Another Child}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Replace+a+Child+with+Another+Child]
|
||||
- {Task: Replace Multiple Children with Another Child}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Replace+Multiple+Children+with+Another+Child]
|
||||
- {Task: Insert Child Before a Given Child}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Insert+Child+Before+a+Given+Child]
|
||||
- {Task: Insert Child After a Given Child}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Insert+Child+After+a+Given+Child]
|
||||
- {Deletions}[../../tasks/rdoc/parent_rdoc.html#label-Deletions]
|
||||
- {Task: Remove a Given Child}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Remove+a+Given+Child]
|
||||
- {Task: Remove the Child at a Specified Offset}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Remove+the+Child+at+a+Specified+Offset]
|
||||
- {Task: Remove Children That Meet Specified Criteria}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Remove+Children+That+Meet+Specified+Criteria]
|
||||
- {Iterations}[../../tasks/rdoc/parent_rdoc.html#label-Iterations]
|
||||
- {Task: Iterate Over Children}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Iterate+Over+Children]
|
||||
- {Task: Iterate Over Child Indexes}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Iterate+Over+Child+Indexes]
|
||||
- {Clones}[../../tasks/rdoc/parent_rdoc.html#label-Clones]
|
||||
- {Task: Clone Deeply}[../../tasks/rdoc/parent_rdoc.html#label-Task-3A+Clone+Deeply]
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
Tasks on this page:
|
||||
|
||||
- {Siblings}[#label-Siblings]
|
||||
- {Task: Find Previous Sibling}[#label-Task-3A+Find+Previous+Sibling]
|
||||
- {Task: Find Next Sibling}[#label-Task-3A+Find+Next+Sibling]
|
||||
- {Position}[#label-Position]
|
||||
- {Task: Find Own Index Among Siblings}[#label-Task-3A+Find+Own+Index+Among+Siblings]
|
||||
- {Recursive Traversal}[#label-Recursive+Traversal]
|
||||
- {Task: Traverse Each Recursively}[#label-Task-3A+Traverse+Each+Recursively]
|
||||
- {Recursive Search}[#label-Recursive+Search]
|
||||
- {Task: Traverse Each Recursively}[#label-Task-3A+Traverse+Each+Recursively]
|
||||
- {Representation}[#label-Representation]
|
||||
- {Task: Represent a String}[#label-Task-3A+Represent+a+String]
|
||||
- {Parent?}[#label-Parent-3F]
|
||||
- {Task: Determine Whether the Node is a Parent}[#label-Task-3A+Determine+Whether+the+Node+is+a+Parent]
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
Tasks on this page:
|
||||
|
||||
- {Queries}[#label-Queries]
|
||||
- {Task: Get the Count of Children}[#label-Task-3A+Get+the+Count+of+Children]
|
||||
- {Task: Get the Child at a Given Index}[#label-Task-3A+Get+the+Child+at+a+Given+Index]
|
||||
- {Task: Get the Index of a Given Child}[#label-Task-3A+Get+the+Index+of+a+Given+Child]
|
||||
- {Task: Get the Children}[#label-Task-3A+Get+the+Children]
|
||||
- {Task: Determine Whether the Node is a Parent}[#label-Task-3A+Determine+Whether+the+Node+is+a+Parent]
|
||||
- {Additions}[#label-Additions]
|
||||
- {Task: Add a Child at the Beginning}[#label-Task-3A+Add+a+Child+at+the+Beginning]
|
||||
- {Task: Add a Child at the End}[#label-Task-3A+Add+a+Child+at+the+End]
|
||||
- {Task: Replace a Child with Another Child}[#label-Task-3A+Replace+a+Child+with+Another+Child]
|
||||
- {Task: Replace Multiple Children with Another Child}[#label-Task-3A+Replace+Multiple+Children+with+Another+Child]
|
||||
- {Task: Insert Child Before a Given Child}[#label-Task-3A+Insert+Child+Before+a+Given+Child]
|
||||
- {Task: Insert Child After a Given Child}[#label-Task-3A+Insert+Child+After+a+Given+Child]
|
||||
- {Deletions}[#label-Deletions]
|
||||
- {Task: Remove a Given Child}[#label-Task-3A+Remove+a+Given+Child]
|
||||
- {Task: Remove the Child at a Specified Offset}[#label-Task-3A+Remove+the+Child+at+a+Specified+Offset]
|
||||
- {Task: Remove Children That Meet Specified Criteria}[#label-Task-3A+Remove+Children+That+Meet+Specified+Criteria]
|
||||
- {Iterations}[#label-Iterations]
|
||||
- {Task: Iterate Over Children}[#label-Task-3A+Iterate+Over+Children]
|
||||
- {Task: Iterate Over Child Indexes}[#label-Task-3A+Iterate+Over+Child+Indexes]
|
||||
- {Clones}[#label-Clones]
|
||||
- {Task: Clone Deeply}[#label-Task-3A+Clone+Deeply]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user