Class: Saxon::XDM::Node
- Inherits:
-
Object
- Object
- Saxon::XDM::Node
- Includes:
- Enumerable, ItemSequenceLike, SequenceLike
- Defined in:
- lib/saxon/xdm/node.rb
Overview
An XPath Data Model Node object, representing an XML document, or an element or one of the other node chunks in the XDM.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Does this Node represent the same underlying node as the other?.
-
#axis_iterator(axis) ⇒ Object
Create an AxisIterator over this Node for the given XPath axis.
-
#each {|node| ... } ⇒ Object
Execute the given block for every child node of this.
-
#hash ⇒ Object
Compute a hash-code for this Node.
-
#initialize(s9_xdm_node) ⇒ Node
constructor
private
A new instance of Node.
-
#node_kind ⇒ Symbol
What kind of node this is.
-
#node_name ⇒ Saxon::QName, null
The name of the node, as a QName, or
nil
if the node is not of a kind that has a name. -
#to_java ⇒ Saxon::S9API::XdmNode
The underlying Saxon Java XDM node object.
-
#to_s ⇒ Object
Use Saxon’s naive XDM Node serialisation to serialize the node and its descendants.
Methods included from ItemSequenceLike
#sequence_enum, #sequence_size
Methods included from SequenceLike
#append, #sequence_enum, #sequence_size
Constructor Details
#initialize(s9_xdm_node) ⇒ Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Node.
18 19 20 |
# File 'lib/saxon/xdm/node.rb', line 18 def initialize(s9_xdm_node) @s9_xdm_node = s9_xdm_node end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Does this Node represent the same underlying node as the other?
61 62 63 64 |
# File 'lib/saxon/xdm/node.rb', line 61 def ==(other) return false unless other.is_a?(XDM::Node) s9_xdm_node.equals(other.to_java) end |
#axis_iterator(axis) ⇒ Object
Create an AxisIterator over this Node for the given XPath axis
85 86 87 |
# File 'lib/saxon/xdm/node.rb', line 85 def axis_iterator(axis) AxisIterator.new(self, axis) end |
#each {|node| ... } ⇒ Object
Execute the given block for every child node of this
78 79 80 |
# File 'lib/saxon/xdm/node.rb', line 78 def each(&block) axis_iterator(:child).each(&block) end |
#hash ⇒ Object
Compute a hash-code for this Saxon::XDM::Node.
Two Saxon::XDM::Nodes with the same content will have the same hash code (and will compare using eql?).
72 73 74 |
# File 'lib/saxon/xdm/node.rb', line 72 def hash @hash ||= s9_xdm_node.hashCode end |
#node_kind ⇒ Symbol
What kind of node this is. Returns one of :document
, :element
, :text
, :attribute
, :namespace
, :comment
, :processing_instruction
, or :comment
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/saxon/xdm/node.rb', line 41 def node_kind @node_kind ||= case s9_xdm_node.nodeKind when Saxon::S9API::XdmNodeKind::ELEMENT :element when Saxon::S9API::XdmNodeKind::TEXT :text when Saxon::S9API::XdmNodeKind::ATTRIBUTE :attribute when Saxon::S9API::XdmNodeKind::NAMESPACE :namespace when Saxon::S9API::XdmNodeKind::COMMENT :comment when Saxon::S9API::XdmNodeKind::PROCESSING_INSTRUCTION :processing_instruction when Saxon::S9API::XdmNodeKind::DOCUMENT :document end end |
#node_name ⇒ Saxon::QName, null
The name of the node, as a QName, or nil
if the node is not of a kind that has a name
30 31 32 33 34 |
# File 'lib/saxon/xdm/node.rb', line 30 def node_name return @node_name if instance_variable_defined?(:@node_name) node_name = s9_xdm_node.getNodeName @node_name = node_name.nil? ? nil : Saxon::QName.new(node_name) end |
#to_java ⇒ Saxon::S9API::XdmNode
Returns The underlying Saxon Java XDM node object.
23 24 25 |
# File 'lib/saxon/xdm/node.rb', line 23 def to_java @s9_xdm_node end |
#to_s ⇒ Object
Use Saxon’s naive XDM Node serialisation to serialize the node and its descendants. Saxon uses a new Serializer with default options to serialize the node. In particular, if the Node was produced by an XSLT that used <xsl:character-map> through <xsl:output> to modify the contents, then they WILL NOT have been applied.
<xsl:output> has its effect at serialization time, not at XDM tree creation time, so it won’t be applied until you serialize the document.
Even then, unless you use a Serializer configured with the XSLT’s <xsl:output>. We make a properly configured serializer available in the result of any XSLT transform (a Saxon::XSLT::Invocation), e.g.:
result = xslt.apply_templates(input)
result.to_s
# or
result.serialize('/path/to/output.xml')
You can also get that Serializer directly from Saxon::XSLT::Executable, should you want to use the serialization options from a particular XSLT to serialize arbitrary XDM values:
serializer = xslt.serializer
serializer.serialize(an_xdm_value)
115 116 117 |
# File 'lib/saxon/xdm/node.rb', line 115 def to_s s9_xdm_node.toString end |