class
   XML::Node
 
  
  Direct Known Subclasses
Defined in:
xml/node.crxml/node/type.cr
Constant Summary
- 
        LOOKS_LIKE_XPATH = /^(\.\/|\/|\.\.|\.$)/
Instance Method Summary
- 
        #==(other : Node)
        
          Compares with other. 
- 
        #[](attribute : String) : String
        
          Gets the attribute content for the attribute given by name. 
- 
        #[]=(name : String, value)
        
          Sets attribute of this node to value. 
- 
        #[]?(attribute : String) : String | Nil
        
          Gets the attribute content for the attribute given by name. 
- 
        #attribute? : Bool
        
          Returns trueif this is an attribute node.
- 
        #attributes : XML::Attributes
        
          Returns attributes of this node as an XML::Attributes.
- 
        #cdata? : Bool
        
          Returns trueif this is aCDATAsection node.
- 
        #children : XML::NodeSet
        
          Gets the list of children for this node as a XML::NodeSet.
- 
        #comment?
        
          Returns trueif this is a comment node.
- 
        #content : String
        
          Returns the content for this Node. 
- 
        #content=(content)
        
          Sets the Node's content to a Text node containing string. 
- 
        #delete(name : String) : String | Nil
        
          Deletes attribute given by name. 
- 
        #document : Document
        
          Gets the document for this node. 
- 
        #document? : Bool
        
          Returns trueif this is a Document or HTML Document node.
- 
        #element? : Bool
        
          Returns trueif this is an Element node.
- 
        #encoding : String | Nil
        
          Returns the encoding of this node's document. 
- 
        #errors : Array(XML::Error) | Nil
        
          DEPRECATED Use XML::Document#errors instead. 
- 
        #first_element_child : XML::Node | Nil
        
          Returns the first child node of this node that is an element. 
- 
        #fragment? : Bool
        
          Returns trueif this is a DocumentFragment.
- #hash(hasher)
- 
        #inner_text : String
        
          Returns the content for this Node. 
- 
        #inspect(io : IO) : Nil
        
          Returns detailed information for this node including node type, name, attributes and children. 
- 
        #name : String
        
          Returns the name for this Node. 
- 
        #name=(name)
        
          Sets the name for this Node. 
- 
        #namespace : Namespace | Nil
        
          Returns the namespace for this node or nilif not found.
- 
        #namespace_definitions : Array(Namespace)
        
          Returns namespaces defined on this node directly. 
- 
        #namespace_scopes : Array(Namespace)
        
          Returns namespaces in scope for this node – those defined on this node directly or any ancestor node – as an ArrayofXML::Namespaceobjects.
- #namespaces : Hash(String, String | Nil)
- 
        #next : XML::Node | Nil
        
          Returns the next sibling node or nilif not found.
- 
        #next_element : XML::Node | Nil
        
          Returns the next element node sibling or nilif not found.
- 
        #next_sibling : XML::Node | Nil
        
          Returns the next sibling node or nilif not found.
- 
        #object_id : UInt64
        
          Returns the address of underlying LibXML::Node*in memory.
- 
        #parent : XML::Node | Nil
        
          Returns the parent node or nilif not found.
- 
        #pretty_print(pp : PrettyPrint) : Nil
        
          Pretty prints selfinto the given printer.
- 
        #previous : XML::Node | Nil
        
          Returns the previous sibling node or nilif not found.
- 
        #previous_element : XML::Node | Nil
        
          Returns the previous sibling node that is an element or nilif not found.
- 
        #previous_sibling : XML::Node | Nil
        
          Returns the previous sibling node or nilif not found.
- 
        #processing_instruction?
        
          Returns trueif this is a Processing Instruction node.
- 
        #root : XML::Node | Nil
        
          Returns the root node for this document or nil.
- 
        #text : String
        
          Same as #content.
- 
        #text=(text)
        
          Same as #content=.
- 
        #text? : Bool
        
          Returns trueif this is a Text node.
- 
        #to_s(io : IO) : Nil
        
          Serialize this Node as XML to io using default options. 
- 
        #to_xml(indent : Int = 2, indent_text = " ", options : SaveOptions = SaveOptions.xml_default) : String
        
          Serialize this Node as XML and return a Stringusing default options.
- 
        #to_xml(io : IO, indent = 2, indent_text = " ", options : SaveOptions = SaveOptions.xml_default)
        
          Serialize this Node as XML to io using default options. 
- 
        #type : XML::Node::Type
        
          Returns the type for this Node as XML::Node::Type.
- 
        #unlink : Nil
        
          Removes the node from the XML document. 
- 
        #version : String | Nil
        
          Returns the version of this node's document. 
- 
        #xml?
        
          Returns trueif this is an xml Document node.
- 
        #xpath(path, namespaces = nil, variables = nil)
        
          Searches this node for XPath path. 
- 
        #xpath_bool(path, namespaces = nil, variables = nil)
        
          Searches this node for XPath path and restricts the return type to Bool.
- 
        #xpath_float(path, namespaces = nil, variables = nil)
        
          Searches this node for XPath path and restricts the return type to Float64.
- 
        #xpath_node(path, namespaces = nil, variables = nil)
        
          Searches this node for XPath path for nodes and returns the first one. 
- 
        #xpath_nodes(path, namespaces = nil, variables = nil)
        
          Searches this node for XPath path and restricts the return type to NodeSet.
- 
        #xpath_string(path, namespaces = nil, variables = nil)
        
          Searches this node for XPath path and restricts the return type to String.
Instance methods inherited from class Reference
  
  
    
      ==(other : self)==(other : JSON::Any)
==(other : YAML::Any)
==(other) ==, dup dup, hash(hasher) hash, initialize initialize, inspect(io : IO) : Nil inspect, object_id : UInt64 object_id, pretty_print(pp) : Nil pretty_print, same?(other : Reference) : Bool
same?(other : Nil) same?, to_s(io : IO) : Nil to_s
Constructor methods inherited from class Reference
  
  
    
      new
    new, 
    
  
    
      unsafe_construct(address : Pointer, *args, **opts) : self
    unsafe_construct
    
  
      
  Class methods inherited from class Reference
  
  
    
      pre_initialize(address : Pointer)
    pre_initialize
    
  
      
    
      
  Instance methods inherited from class Object
  
  
    
      ! : Bool
    !, 
    
  
    
      !=(other)
    !=, 
    
  
    
      !~(other)
    !~, 
    
  
    
      ==(other)
    ==, 
    
  
    
      ===(other : JSON::Any)===(other : YAML::Any)
===(other) ===, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash hash, in?(collection : Object) : Bool
in?(*values : Object) : Bool in?, inspect(io : IO) : Nil
inspect : String inspect, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil!(message)
not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String to_json, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil to_pretty_json, to_s(io : IO) : Nil
to_s : String to_s, to_yaml(io : IO) : Nil
to_yaml : String to_yaml, try(&) try, unsafe_as(type : T.class) forall T unsafe_as
Class methods inherited from class Object
  
  
    
      from_json(string_or_io, root : String)from_json(string_or_io) from_json, from_yaml(string_or_io : String | IO) from_yaml
Macros inherited from class Object
  
  
    
      class_getter(*names, &block)
    class_getter, 
    
  
    
      class_getter!(*names)
    class_getter!, 
    
  
    
      class_getter?(*names, &block)
    class_getter?, 
    
  
    
      class_property(*names, &block)
    class_property, 
    
  
    
      class_property!(*names)
    class_property!, 
    
  
    
      class_property?(*names, &block)
    class_property?, 
    
  
    
      class_setter(*names)
    class_setter, 
    
  
    
      def_clone
    def_clone, 
    
  
    
      def_equals(*fields)
    def_equals, 
    
  
    
      def_equals_and_hash(*fields)
    def_equals_and_hash, 
    
  
    
      def_hash(*fields)
    def_hash, 
    
  
    
      delegate(*methods, to object)
    delegate, 
    
  
    
      forward_missing_to(delegate)
    forward_missing_to, 
    
  
    
      getter(*names, &block)
    getter, 
    
  
    
      getter!(*names)
    getter!, 
    
  
    
      getter?(*names, &block)
    getter?, 
    
  
    
      property(*names, &block)
    property, 
    
  
    
      property!(*names)
    property!, 
    
  
    
      property?(*names, &block)
    property?, 
    
  
    
      setter(*names)
    setter
    
  
    
  Instance Method Detail
Gets the attribute content for the attribute given by name.
Raises KeyError if attribute is not found.
Gets the attribute content for the attribute given by name.
Returns nil if attribute is not found.
Returns the content for this Node. An empty string is returned if the node has no content.
Sets the Node's content to a Text node containing string. The string gets XML escaped, not interpreted as markup.
Deletes attribute given by name.
Returns attributes value, or nil if attribute not found.
Returns the first child node of this node that is an element.
Returns nil if not found.
Returns detailed information for this node including node type, name, attributes and children.
Returns namespaces in scope for this node – those defined on this node
directly or any ancestor node – as an Array of XML::Namespace objects.
Default namespaces ("xmlns=" style) for this node are included in this
array; default namespaces for ancestors, however, are not.
See also #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 this node – those defined on this node
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.
Pretty prints self into the given printer.
By default appends a text that is the result of invoking
#inspect on self. Subclasses should override
for custom pretty printing.
Returns the previous sibling node that is an element or nil if not found.
Serialize this Node as XML and return a String using default options.
See XML::SaveOptions.xml_default for default options.
Serialize this Node as XML to io using default options.
See XML::SaveOptions.xml_default for default options.
Searches this node for XPath path. Returns result with appropriate type
(Bool | Float64 | String | XML::NodeSet).
Raises XML::Error on evaluation error.
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") # => trueSearches 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.0Searches 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") # => nilSearches 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"]