Class Openwsman::XmlNode
In: ../openwsman.i
openwsman/xmlnode.rb
Parent: Object

XmlNode is a node inside the XML document tree.

A node has

  • a name
  • a namespace (optional)
  • attributes
  • text (optional)
  • a parent
  • a document (root)
  • children (empty for tail nodes)

Methods

<<   []   add   add_before   attr   attr_add   attr_count   attr_find   child   doc   dump_file   each   each_attr   epr   find   first   get   lang=   name   name=   next   ns   ns=   parent   prefix   size   text=   toString   toXML  

External Aliases

text -> to_s
string -> to_xml
equal -> ==

Public Instance methods

<<(p1, p2, p3)

Alias for add

[](p1, p2, p3)

Alias for get

add child (namespace, name, text) to node

add child (namespace, name, text) before(!) node

count node attribute

get XmlDoc to which node belongs

iterate over children

See also XmlNode#next

XmlNode#each iterates over children, XmlNode#next over siblings

can be limited to children with specific name (and specific namespace)

for array-like constructs, e.g

 <Parent>
   <Child>..
   <Child>..
   <Child>..
   <OtherChild>..
   <OtherChild>..
   <OtherChild>..

  doc.Parent.each do |child|
    ... iterates over all 6 children ...
  end

use XmlNode#next as in

  node = doc.OtherChild
  while node do
    ... do something with node ...
   node = node.next
  end
first()

Alias for child

iterate over siblings

finds next sibling with same namespace and name

See also XmlNode#each

XmlNode#each iterates over children, XmlNode#next over siblings

Example:

   <Foo>
     <Bar>...
     <Bar>...
     <Bar>...
     <Bar>...
     <Other>...
     <Other>...
   </Foo>

node = root.Foo # points to <Foo> node

  bar = node.Bar
  while bar do
    bar = bar.next
  end

will give you four iterations (all <Bar> nodes)

  child = node.Bar
  while child do
    child = child.next(1)
  end

will give you six iterations (all children of <Foo>) The latter example is equal to

  node.each do |child|
    ...
  end

get namespace for node

set namespace of node

count node children if name given, count children with this name if name + ns given, count children with this namespace and name

Set text of node

get text (without xml tags) of node

alias: to_s

dump node as XML string

alias: to_xml

[Validate]