W3cubDocs

/Crystal 0.31

struct XML::Node

Defined in:

xml/node.cr
xml/node/type.cr

Constant Summary

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

Constructors

Instance Method Summary

Constructor Detail

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

Creates a new node.

def self.new(node : Pointer(LibXML::Doc))Source

Creates a new node.

def self.new(node : Pointer(LibXML::Node))Source

Creates a new node.

Instance Method Detail

def ==(other : Node)Source

Compares with other.

def [](attribute : String) : StringSource

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

def []=(name : String, value)Source

Sets attribute of this node to value. Raises XML::Error if this node does not support attributes.

def []?(attribute : String) : String?Source

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

def attribute?Source

Returns true if this is an attribute node.

def attributesSource

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

def cdata?Source

Returns true if this is a CDATA section node.

def childrenSource

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

def comment?Source

Returns true if this is a comment node.

def content : StringSource

Returns the content for this Node. An empty string is returned if the node has no content.

def content=(content)Source

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

def delete(name : String)Source

Deletes attribute given by name. Returns attributes value, or nil if attribute not found.

def documentSource

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

def document?Source

Returns true if this is a Document or HTML Document node.

def element?Source

Returns true if this is an Element node.

def encodingSource

Returns the encoding of this node's document.

def errorsSource

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

def first_element_childSource

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

def fragment?Source

Returns true if this is a DocumentFragment.

def hash(hasher)Source

def inner_textSource

Returns the content for this Node.

def inspect(io : IO) : NilSource

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

def nameSource

Returns the name for this Node.

def name=(name)Source

Sets the name for this Node.

def namespaceSource

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

def namespace_scopesSource

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

def namespacesSource

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 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.

def nextSource

Returns the next sibling node or nil if not found.

def next_elementSource

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

def next_siblingSource

Returns the next sibling node or nil if not found.

def object_idSource

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

def parentSource

Returns the parent node or nil if not found.

def previousSource

Returns the previous sibling node or nil if not found.

def previous_elementSource

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

def previous_siblingSource

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

def processing_instruction?Source

Returns true if this is a Processing Instruction node.

def rootSource

Returns the root node for this document or nil.

def textSource

Same as #content.

def text=(text)Source

Same as #content=.

def text?Source

Returns true if this is a Text node.

def to_s(io : IO) : NilSource

Serialize this Node as XML to io using default options.

See #to_xml.

def to_unsafe : Pointer(LibXML::Node)Source

Returns underlying LibXML::Node* instance.

def to_xml(indent : Int = 2, indent_text = " ", options : SaveOptions = SaveOptions.xml_default)Source

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

See XML::SaveOptions.xml_default for default options.

def to_xml(io : IO, indent = 2, indent_text = " ", options : SaveOptions = SaveOptions.xml_default)Source

Serialize this Node as XML to io using default options.

See XML::SaveOptions.xml_default for default options.

def typeSource

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

def unlinkSource

Removes the node from the XML document.

def versionSource

Returns the version of this node's document.

def xml?Source

Returns true if this is an xml Document node.

def xpath(path, namespaces = nil, variables = nil)Source

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

Raises XML::Error on evaluation error.

def xpath_bool(path, namespaces = nil, variables = nil)Source

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

require "xml"

doc = XML.parse("<person></person>")

doc.xpath_bool("count(//person) > 0") # => true

def xpath_float(path, namespaces = nil, variables = nil)Source

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

require "xml"

doc = XML.parse("<person></person>")

doc.xpath_float("count(//person)") # => 1.0

def xpath_node(path, namespaces = nil, variables = nil)Source

Searches this node for XPath path for nodes and returns the first one. or nil if not found

require "xml"

doc = XML.parse("<person></person>")

doc.xpath_node("//person")  # => #<XML::Node:0x2013e80 name="person">
doc.xpath_node("//invalid") # => nil

def xpath_nodes(path, namespaces = nil, variables = nil)Source

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

require "xml"

doc = XML.parse("<person></person>")

nodes = doc.xpath_nodes("//person")
nodes.class       # => XML::NodeSet
nodes.map(&.name) # => ["person"]

def xpath_string(path, namespaces = nil, variables = nil)Source

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

require "xml"

doc = XML.parse("<person></person>")

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

© 2012–2019 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.31.1/XML/Node.html