struct XML::Node

Defined in:

xml/node.cr

Constant Summary

LOOKS_LIKE_XPATH = /^(\.\/|\/|\.\.|\.$)/

Class Method Summary

Instance Method Summary

Instance methods inherited from struct Struct

==(other : self) : Bool ==, hash : Int32 hash, inspect(io : IO) : Nil inspect, to_s(io) to_s

Instance methods inherited from struct Value

==(other) ==

Instance methods inherited from class Object

!=(other) !=, !~(other) !~, ==(other) ==, ===(other)
===(other : YAML::Any)
===(other : JSON::Any)
===
, =~(other) =~, class class, clone clone, crystal_type_id crystal_type_id, dup dup, hash hash, inspect
inspect(io : IO)
inspect
, itself itself, not_nil! not_nil!, tap(&block) tap, to_json to_json, to_pretty_json(io : IO)
to_pretty_json
to_pretty_json
, to_s
to_s(io : IO)
to_s
, to_yaml(io : IO)
to_yaml
to_yaml
, try(&block) try

Class methods inherited from class Object

==(other : Class) ==, ===(other) ===, cast(other) : self cast, from_json(string_or_io) : self from_json, from_yaml(string : String) : self from_yaml, hash hash, inspect(io) inspect, name : String name, to_s(io) to_s, |(other : U.class) |

Class Method Detail

def self.new(node : Pointer(LibXML::Attr)) #

Creates a new node.


[View source]
def self.new(node : Pointer(LibXML::Doc)) #

Creates a new node.


[View source]
def self.new(node : Pointer(LibXML::Node)) #

Creates a new node.


[View source]

Instance Method Detail

def ==(other : Node) #

Compares with other.


[View source]
def [](attribute : String) #

Gets the attribute content for the attribute given by name. Raises KeyError if attribute is not found.


[View source]
def []?(attribute : String) #

Gets the attribute content for the attribute given by name. Returns nil if attribute is not found.


[View source]
def attribute? #

Returns true if this is an attribute node.


[View source]
def attributes #

Returns attributes of this node as an XML::Attributes.


[View source]
def cdata? #

Returns true if this is a CDATA section node.


[View source]
def children #

Gets the list of children for this node as a XML::NodeSet.


[View source]
def comment? #

Returns true if this is a comment node.


[View source]
def content #

Returns the content for this Node. Returns nil if node does not have any content.


[View source]
def content=(content) #

Sets the Node's content to a Text node containing string. The string gets XML escaped, not interpreted as markup.


[View source]
def document #

Gets the document for this Node as a XML::Node.


[View source]
def document? #

Returns true if this is a Document node.


[View source]
def element? #

Returns true if this is an Element node.


[View source]
def encoding #

Returns the encoding of this node's document


[View source]
def errors #

Returns the list of XML::Error found when parsing this document. Returns nil if no errors were found.


[View source]
def first_element_child #

Returns the first child node of this node that is an element. Returns nil if not found.


[View source]
def fragment? #

Returns true if this is a DocumentFragment.


[View source]
def hash #

Returns this node's #object_id as the hash value.


[View source]
def inner_text #

Returns the content for this Node.


[View source]
def inspect(io) #

Returns detailed information for this node including node type, name, attributes and children.


[View source]
def name #

Returns the name for this Node.


[View source]
def name=(name) #

Sets the name for this Node.


[View source]
def namespace #

Returns the namespace for this node or nil if not found.


[View source]
def namespace_scopes #

Returns namespaces in scope for self – those defined on self element directly or any ancestor node – as an Array of XML::Namespace objects. Default namespaces ("xmlns=" style) for self are included in this array; Default namespaces for ancestors, however, are not. See also #namespaces


[View source]
def namespaces #

Returns a Hash(String, String?) of prefix => href for all namespaces on this node and its ancestors.

This method returns the same namespaces as #namespace_scopes.

Returns namespaces in scope for self – those defined on self element directly or any ancestor node – as a Hash of attribute-name/value pairs. Note that the keys in this hash XML attributes that would be used to define this namespace, such as "xmlns:prefix", not just the prefix.


[View source]
def next #

Returns the next sibling node or nil if not found.


[View source]
def next_element #

Returns the next element node sibling or nil if not found.


[View source]
def next_sibling #

Returns the next sibling node or nil if not found.


[View source]
def object_id #

Returns the address of underlying LibXML::Node* in memory,


[View source]
def parent #

Returns the parent node or nil if not found.


[View source]
def previous #

Returns the previous sibling node or nil if not found.


[View source]
def previous_element #

Returns the previous sibling node that is an element or nil if not found.


[View source]
def previous_sibling #

Returns the previous sibling node or nil if not found. Same with #previous.


[View source]
def processing_instruction? #

Returns true if this is a Processing Instruction node.


[View source]
def root #

Returns the root node for this document or nil.


[View source]
def text #

Same as #content.


[View source]
def text=(text) #

Same as #content=.


[View source]
def text? #

Returns true if this is a Text node.


[View source]
def to_s(io : IO) #

Serialize this Node as XML to io using default options. See #to_xml.


[View source]
def to_unsafe : Pointer(LibXML::Node) #

Returns underlying LibXML::Node* instance.


[View source]
def to_xml(indent : Int = 2, indent_text = " ", options : SaveOptions = SaveOptions.xml_default) #

Serialize this Node as XML and return a String using default options.

See XML::SaveOptions.xml_default for default options.


[View source]
def to_xml(io : IO, indent = 2, indent_text = " ", options : SaveOptions = SaveOptions.xml_default) #

Serialize this Node as XML to io using default options.

See XML::SaveOptions.xml_default for default options.


[View source]
def type #

Returns the type for this Node as XML::Type.


[View source]
def version #

Returns the version of this node's document


[View source]
def xml? #

Returns true if this is an xml Document node.


[View source]
def xpath(path, namespaces = nil, variables = nil) #

Searches this node for XPath path. Returns result with appropriate type (Bool | Float64 | String | XML::NodeSet). Raises XML::Error on evaluation error.


[View source]
def xpath_bool(path, namespaces = nil, variables = nil) #

Searches this node for XPath path and restricts the return type to Bool.

node.xpath_bool("count(//person) > 0")

[View source]
def xpath_float(path, namespaces = nil, variables = nil) #

Searches this node for XPath path and restricts the return type to Float64.

node.xpath_float("count(//person)")

[View source]
def xpath_node(path, namespaces = nil, variables = nil) #

Searches this node for XPath path for nodes and returns the first one.

node.xpath_node("//person")

[View source]
def xpath_nodes(path, namespaces = nil, variables = nil) #

Searches this node for XPath path and restricts the return type to NodeSet.

node.xpath_nodes("//person")

[View source]
def xpath_string(path, namespaces = nil, variables = nil) #

Searches this node for XPath path and restricts the return type to String.

node.xpath_string("string(/persons/person[1])")

[View source]