Class: XmlObject
- Inherits:
-
XmlInterface
- Object
- XmlInterface
- XmlObject
- Defined in:
- lib/xmlobject/doc.rb,
lib/xmlobject/config.rb,
lib/xmlobject/object.rb
Overview
XmlObject is a Xml abstraction for both REXML and libxml. If libxml is present use it, if not switch to slower implementation REXML.
Before anything else, begin with :
require 'xmlobject'
For example, you have this xml in the “buffer” variable :
<root_tag attr_string="foo" attr_int="1" attr_int_false="0">
<children>
<child name='1'/>
<child name='2'/>
<child name='3'/>
</children>
<some_text>
FooBar
</some_text>
</root_tag>
Create an XmlObject :
xml = XmlObject.new(buffer)
Then get the root attributes :
puts xml.attr_string -> foo
puts xml['attr_string'] -> foo
puts xml.attr_int -> 1
Ask if some attributes or child are present or true :
puts xml.attr_string? -> true
puts xml.not_here? -> false
puts xml.attr_int? -> true
puts xml.attr_int_false? -> false
puts xml.children? -> true
Iter through children :
xml.children.child do |child|
puts child.name -> 1, 2, 3
end
Get some text :
puts xml.some_text.text.strip
Constant Summary collapse
- NAME =
'XmlObject'
- VERSION =
'0.2'
- COPYRIGHT =
'Copyright (C) 2007 Florent Solt'
- DESC =
'Xml object abstraction for both REXML and libxml'
- AUTHOR =
'Florent Solt'
- EMAIL =
'[email protected]'
- HOMEPAGE =
'http://grtm.rubyforge.org'
- LICENSE =
'BSD'
Instance Method Summary collapse
-
#[](name) ⇒ Object
:nodoc:.
-
#initialize(xml) ⇒ XmlObject
constructor
:nodoc:.
-
#method_missing(name, *args, &block) ⇒ Object
:nodoc:.
-
#methods ⇒ Object
:nodoc:.
-
#text ⇒ Object
:nodoc:.
Methods inherited from XmlInterface
Constructor Details
#initialize(xml) ⇒ XmlObject
:nodoc:
46 47 |
# File 'lib/xmlobject/doc.rb', line 46 def initialize(xml) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
:nodoc:
74 75 |
# File 'lib/xmlobject/doc.rb', line 74 def method_missing(name, *args) end |
Instance Method Details
#[](name) ⇒ Object
:nodoc:
50 51 |
# File 'lib/xmlobject/doc.rb', line 50 def [](name) end |
#methods ⇒ Object
:nodoc:
60 61 |
# File 'lib/xmlobject/doc.rb', line 60 def methods end |
#text ⇒ Object
:nodoc:
54 55 |
# File 'lib/xmlobject/doc.rb', line 54 def text end |