Module | XML |
In: |
lib/s33r/libxml_extensions.rb
|
Convenience methods for libxml classes.
Parse an XML string into an XML::Document instance.
# File lib/s33r/libxml_extensions.rb, line 19 19: def XML.get_xml_doc(xml_str) 20: parser = XML::Parser.new 21: parser.string = xml_str 22: parser.parse 23: end
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.
# File lib/s33r/libxml_extensions.rb, line 9 9: def xget(xpath) 10: nodes = self.find(xpath).to_a 11: if nodes.empty? 12: return nil 13: else 14: return nodes.first.content 15: end 16: end