Object
Creates a new document based on the specified document.
Parameters:
document - A preparsed document.
# File lib/libxml/document.rb, line 14 14: def self.document(value) 15: Parser.document(value).parse 16: end
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 (|).
# File lib/libxml/document.rb, line 33 33: def self.file(value, options = {}) 34: Parser.file(value, options).parse 35: end
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 (|).
# File lib/libxml/document.rb, line 54 54: def self.io(value, options = {}) 55: Parser.io(value, options).parse 56: end
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 (|).
# File lib/libxml/document.rb, line 75 75: def self.string(value, options = {}) 76: Parser.string(value, options).parse 77: end
Returns a new XML::XPathContext for the document.
Namespaces is an optional array of XML::NS objects
# File lib/libxml/document.rb, line 85 85: def context(nslist = nil) 86: context = XPath::Context.new(self) 87: context.node = self.root 88: context.register_namespaces_from_node(self.root) 89: context.register_namespaces(nslist) if nslist 90: context 91: end
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:
xpath - The xpath expression as a string
namespaces - An optional list of namespaces (see XML::XPath for information).
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
# File lib/libxml/document.rb, line 122 122: def find(xpath, nslist = nil) 123: self.context(nslist).find(xpath) 124: end
Return the first node matching the specified xpath expression. For more information, please refer to the documentation for XML::Document#find.
# File lib/libxml/document.rb, line 129 129: def find_first(xpath, nslist = nil) 130: find(xpath, nslist).first 131: end
Returns this node’s type name
# File lib/libxml/document.rb, line 134 134: def node_type_name 135: case node_type 136: when XML::Node::DOCUMENT_NODE 137: 'document_xml' 138: when XML::Node::DOCB_DOCUMENT_NODE 139: 'document_docbook' 140: when XML::Node::HTML_DOCUMENT_NODE 141: 'document_html' 142: else 143: raise(UnknownType, "Unknown node type: %n", node.node_type); 144: end 145: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.