Module: Libxml4r::XML::Document
- Defined in:
- lib/libxml4r.rb
Instance Method Summary (collapse)
-
- (Object) last=(node)
:call-seq:.
-
- (Object) node
:call-seq:.
-
- (Object) node_at(xpath)
:nodoc:.
-
- (Object) nodes
:call-seq:.
-
- (Object) nodes_at(xpath)
:nodoc:.
-
- (Object) strip!
(also: #strip_namespaces!)
:call-seq:.
-
- (Object) to_xml
:call-seq:.
Instance Method Details
- (Object) last=(node)
:call-seq:
doc.last = node -> XML::Node
Appends node to the end of the list of nodes at this level
14 15 16 |
# File 'lib/libxml4r.rb', line 14 def last=(node) self.last? ? self.root.sibling=node : self.root = node end |
- (Object) node
:call-seq:
doc.node["/xpath"] -> XML::Node
Returns the first Node object matching "/xpath", or nil if no object could not be found.
Note its usually recommended to remove all namespaces with strip! before xpath traversal.
24 25 26 |
# File 'lib/libxml4r.rb', line 24 def node() self.root.node() end |
- (Object) node_at(xpath)
:nodoc:
28 29 30 |
# File 'lib/libxml4r.rb', line 28 def node_at(xpath) #:nodoc: self.root.node_at(xpath) end |
- (Object) nodes
:call-seq:
doc.nodes["/xpath"] -> [XML::Node, XML::Node, XML::Node, ...]
Returns an array containing all nodes matching "/xpath", or nil if no object could not be found.
Note its usually recommended to remove all namespaces with strip! before xpath traversal.
38 39 40 |
# File 'lib/libxml4r.rb', line 38 def nodes() self.root.nodes() end |
- (Object) nodes_at(xpath)
:nodoc:
42 43 44 |
# File 'lib/libxml4r.rb', line 42 def nodes_at(xpath) #:nodoc: self.root.search(xpath) end |
- (Object) strip! Also known as: strip_namespaces!
:call-seq:
doc.strip! -> XML::Document
doc.strip_namespaces! -> XML::Document
Strip all namespaces from this XML::Document. replaces the root node with a stripped XML::Node (and children)
Note Xml elements with a namespace context are usually omited from xpath search criteria.
See: libxml.rubyforge.org/rdoc/classes/LibXML/XML/XPath.html
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/libxml4r.rb', line 56 def strip! # Parse xml xml_str = self.to_s # puts "xml_str=#{xml_str}\\n" xml_str.gsub! /\ ?(soap|xmlns)(:\w*)?=\"[^\"]*\"/, "" xml_str.gsub! /\<\w*:/, "<" xml_str.gsub! /\<\/\w*:/, "</" # puts "xml_str=#{xml_str}\\n" xml_doc_stripped = xml_str.to_xmldoc self.root = xml_doc_stripped.root.copy(true) return self end |
- (Object) to_xml
74 75 76 |
# File 'lib/libxml4r.rb', line 74 def to_xml return self.to_s end |