Sha256: 24eec33e9045d2bb326cb78abe7f86c787c574eec190f1b201408cae971a5764

Contents?: true

Size: 565 Bytes

Versions: 1

Compression:

Stored size: 565 Bytes

Contents

# convenience methods for libxml classes
module XML
  # find first matching element and return its content
  # xpath: XPath query
  # 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

  class Document
    include XML
  end

  class Node
    include XML
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
s33r-0.2 lib/s33r/libxml_extensions.rb