Xml

Parent

Namespace

Generated with Razzle Dazzle Redfish.
[Validate]

Constants

VALID_CLASSES
(Not documented)

Public Class Methods

__new( xmldata, parent=nil ) click to toggle source

Alias for new

new( xmldata, parent=nil ) click to toggle source

(Not documented)

# File lib/r4x/e4x.rb, line 52
    def new( xmldata, parent=nil )
      case xmldata
      when nil, ''
        raise ArgumentError
      when Xml, Symbol, XmlCanonical
        __new( xmldata, parent )
      when REXML::Element, REXML::Text, REXML::Attribute, REXML::Instruction
        __new( xmldata, parent )
      else
        XmlList.new(xmldata, parent)
      end
    end
Also aliased as: __new
new( xmldata, parent=nil ) click to toggle source

(Not documented)

# File lib/r4x/e4x.rb, line 66
  def initialize( xmldata, parent=nil )
    @parent = parent
    case xmldata
    when Xml
      @node = xmldata.__node.dup
      @class = xmldata.__class.dup
      @name = xmldata.__node.name.dup
    when Symbol
      #@node = REXML::Document.new( "<#{xmldata}></#{xmldata}>" ).root
      #@node = REXML::Element.new( "<#{xmldata}></#{xmldata}>" ).root
      @node = REXML::Element.new( xmldata )
      @class = :element
      @name = @node.name
    when XmlCanonical
      xmldata = xmldata.to_s
      @node = REXML::Document.new( xmldata.strip ).root
      #@node = REXML::Element.new( xmldata.strip )
      @class = :element
      @name = @node.name
    when REXML::Element
      @node = xmldata
      @class = :element
      @name = @node.name
    when REXML::Text
      @node = xmldata
      @class = :text
      @name = nil
    when REXML::Attribute
      @node = xmldata
      @class = :attribute
      @name = xmldata.name
    when REXML::Instruction
      @node = xmldata
      @class = :instruction
      @name = xmldata.target
    else
      raise ArgumentError, "invlaid xml"
    end
    @self ||= XmlDelegate.new(self)
  end

Public Instance Methods

*() click to toggle source

XPath for all elements.

# File lib/r4x/e4x.rb, line 144
  def * ; @self.get('*') ; end
<<( n ) click to toggle source

Shortcut for add.

# File lib/r4x/e4x.rb, line 139
  def <<( n )
    @self.add( n )
  end
[]( key ) click to toggle source

XPath get operator.

# File lib/r4x/e4x.rb, line 150
  def []( key )
    @self.get( key )
  end
[]=( key, val ) click to toggle source

XPath put operator.

# File lib/r4x/e4x.rb, line 155
  def []=( key, val )
    @self.put( key, val )
  end
_() click to toggle source

Shortcut for XPath ’@*’, meaning all attributes.

# File lib/r4x/e4x.rb, line 147
  def _ ; @self.get('@*') ; end
__class() click to toggle source

This is how the delegate accesses the node classification.

# File lib/r4x/e4x.rb, line 125
  def __class ; @class ; end
__node() click to toggle source

This is how the delegate accesses the node.

# File lib/r4x/e4x.rb, line 122
  def __node  ; @node ; end
each() click to toggle source

(neccessary?) FIX!!!

# File lib/r4x/e4x.rb, line 134
  def each()
    @node.each_child { |c| yield(c) }
  end
method_missing( sym, *args ) click to toggle source

Here’s where all the fun’s at! It’s more complicated then it looks ;-)

# File lib/r4x/e4x.rb, line 161
  def method_missing( sym, *args )
    sym = sym.to_s
    if sym.slice(-1) == '='
      self["#{sym.pop}"] = args[0]
    else
      self["#{sym}"]
    end
  end
self() click to toggle source

This is how to access the underlying Xml object, i.e. via the delegate.

# File lib/r4x/e4x.rb, line 119
  def self ; @self ; end
to_i() click to toggle source

?

# File lib/r4x/e4x.rb, line 131
  def to_i() @node.to_s.to_i; end
to_s() click to toggle source

Important for this to work in string interpolation.

# File lib/r4x/e4x.rb, line 128
  def to_s() @node.to_s ; end

Disabled; run with --debug to generate this.