Module: XML
Overview
Convenience methods for libxml classes.
Defined Under Namespace
Class Method Summary collapse
-
.get_xml_doc(xml_str) ⇒ Object
Parse an XML string into an XML::Document instance.
Instance Method Summary collapse
-
#xget(xpath) ⇒ Object
Find first element matching
xpath
and return its content (intended for use as a mixed-in method for Document/Node instances).
Class Method Details
.get_xml_doc(xml_str) ⇒ Object
Parse an XML string into an XML::Document instance.
19 20 21 22 23 |
# File 'lib/s33r/libxml_extensions.rb', line 19 def self.get_xml_doc(xml_str) parser = XML::Parser.new parser.string = xml_str parser.parse end |
Instance Method Details
#xget(xpath) ⇒ Object
Find first element matching xpath
and return its content (intended for use as a mixed-in method for Document/Node instances).
xpath
: XPath query to run against self.
Returns nil if no element matches xpath
.
9 10 11 12 13 14 15 16 |
# File 'lib/s33r/libxml_extensions.rb', line 9 def xget(xpath) nodes = self.find(xpath).to_a if nodes.empty? return nil else return nodes.first.content end end |