Class | LibXML::XML::Document |
In: |
lib/libxml/document.rb
|
Parent: | Object |
Creates a new document from the specified file or uri.
You may provide an optional hash table to control how the parsing is performed. Valid options are:
encoding - The document encoding, defaults to nil. Valid values are the encoding constants defined on XML::Encoding. options - Parser options. Valid values are the constants defined on XML::Parser::Options. Mutliple options can be combined by using Bitwise OR (|).
Creates a new document from the specified io object.
Parameters:
io - io object that contains the xml to parser base_uri - The base url for the parsed document. encoding - The document encoding, defaults to nil. Valid values are the encoding constants defined on XML::Encoding. options - Parser options. Valid values are the constants defined on XML::Parser::Options. Mutliple options can be combined by using Bitwise OR (|).
Creates a new document from the specified string.
You may provide an optional hash table to control how the parsing is performed. Valid options are:
base_uri - The base url for the parsed document. encoding - The document encoding, defaults to nil. Valid values are the encoding constants defined on XML::Encoding. options - Parser options. Valid values are the constants defined on XML::Parser::Options. Mutliple options can be combined by using Bitwise OR (|).
Returns a new XML::XPathContext for the document.
Namespaces is an optional array of XML::NS objects
Return the nodes matching the specified xpath expression, optionally using the specified namespace. For more information about working with namespaces, please refer to the XML::XPath documentation.
Parameters:
document.find('/foo', 'xlink:http://www.w3.org/1999/xlink')
IMPORTANT - The returned XML::Node::Set must be freed before its associated document. In a running Ruby program this will happen automatically via Ruby‘s mark and sweep garbage collector. However, if the program exits, Ruby does not guarantee the order in which objects are freed (see blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/17700). As a result, the associated document may be freed before the node list, which will cause a segmentation fault. To avoid this, use the following (non-ruby like) coding style:
nodes = doc.find('/header') nodes.each do |node| ... do stuff ... end
# nodes = nil # GC.start
Return the first node matching the specified xpath expression. For more information, please refer to the documentation for XML::Document#find.