Sha256: 342fc8670a21870d015a0884285b8dc9e077224ec55bdf3d4ae0c25d77cd3bf1
Contents?: true
Size: 788 Bytes
Versions: 2
Compression:
Stored size: 788 Bytes
Contents
# Convenience methods for libxml classes. module XML # 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+. 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.4.1 | lib/s33r/libxml_extensions.rb |
s33r-0.4 | lib/s33r/libxml_extensions.rb |