Sha256: 769b16a6d69788c76bfe0c390061b499e807a880ed3c02be3b5e95bc6a083044
Contents?: true
Size: 775 Bytes
Versions: 2
Compression:
Stored size: 775 Bytes
Contents
# Convenience methods for libxml classes. module XML # Find first matching element and return its content # (intended for use as a mixed-in method for Document instances). # # +xpath+: XPath query to run against self. # # Returns nil if no element matches +xpath+. def xget(xpath) nodes = self.find(xpath).to_a if nodes.empty? return nil else return nodes.first.content end end # Parse an XML string into an XML::Document instance. def XML.get_xml_doc(xml_str) parser = XML::Parser.new parser.string = xml_str parser.parse end # Make custom methods accessible to Document class. class Document include XML end # Make custom methods accessible to Node class. class Node include XML end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
s33r-0.3.1 | lib/s33r/libxml_extensions.rb |
s33r-0.3 | lib/s33r/libxml_extensions.rb |