- README

- Top Level Namespace
- Adler32
- ArgumentError
- Array
- Atomic
- Base64
  - Error
- Benchmark
  - BM
    - Job
    - Tms
  - IPS
    - Entry
    - Job
- BigFloat
- BigInt
- BigRational
- BitArray
- Bool
- Box
- Bytes
- Channel
  - Buffered
  - ClosedError
  - ReceiveAction
  - SelectAction
  - SendAction
  - Unbuffered
- Char
  - Reader
- Class
- Colorize
  - Object
  - ObjectExtensions
- Comparable
- Complex
- Concurrent
  - CanceledError
- CRC32
- Crypto
  - Bcrypt
    - Error
    - Password
  - Blowfish
  - Subtle
- CSV
  - Builder
    - Row
  - Error
  - Lexer
  - MalformedCSVError
  - Parser
  - Row
  - Token
    - Kind
- Debug
  - DWARF
    - Abbrev
      - Attribute
    - AT
    - FORM
    - Info
      - Value
    - LineNumbers
      - Register
      - Row
      - Sequence
    - LNE
    - LNS
    - Strings
    - TAG
  - ELF
    - Endianness
    - Error
    - Ident
    - Klass
    - Machine
    - OSABI
    - SectionHeader
      - Flags
      - Type
    - Type
- Deque
- Digest
  - Base
  - MD5
  - SHA1
- Dir
- DivisionByZero
- DL
- ECR
- Enum
- Enumerable
  - EmptyError
- ENV
- Errno
- Exception
- Fiber
- File
  - Stat
- FileUtils
- Flate
  - Error
  - Reader
  - Strategy
  - Writer
- Float
  - Primitive
- Float32
- Float64
- GC
  - Stats
- Gzip
  - Error
  - Header
  - Reader
  - Writer
- Hash
- HTML
- HTTP
  - Client
    - BodyType
    - Response
  - CompressHandler
  - ComputedContentTypeHeader
  - Cookie
  - Cookies
  - ErrorHandler
  - FormData
    - Builder
    - Error
    - FileMetadata
    - Parser
    - Part
  - Handler
    - Proc
  - Headers
  - LogHandler
  - Multipart
    - Builder
    - Error
    - Parser
  - Params
    - Builder
  - Request
  - Server
    - Context
    - RequestProcessor
    - Response
  - StaticFileHandler
    - DirectoryListing
  - WebSocket
  - WebSocketHandler
- Indexable
- IndexError
- INI
- Int
  - Primitive
  - Signed
  - Unsigned
- Int16
- Int32
- Int64
- Int8
- InvalidByteSequenceError
- IO
  - Buffered
  - ByteFormat
    - BigEndian
    - LittleEndian
    - NetworkEndian
    - SystemEndian
  - Delimited
  - EncodingOptions
  - EOFError
  - Error
  - FileDescriptor
  - Hexdump
  - Memory
  - MultiWriter
  - Seek
  - Sized
  - Timeout
- IPSocket
- Iterable
- Iterator
  - IteratorWrapper
  - Stop
- JSON
  - Any
  - Builder
    - ArrayState
    - DocumentEndState
    - DocumentStartState
    - ObjectState
    - StartState
    - State
  - Error
  - Lexer
  - ParseException
  - Parser
  - PullParser
  - Token
  - Type
- KeyError
- Levenshtein
  - Finder
- LLVM
  - ABI
    - AArch64
    - ArgKind
    - ArgType
    - ARM
    - FunctionType
    - X86
    - X86_64
      - RegClass
  - AtomicOrdering
  - AtomicRMWBinOp
  - Attribute
  - AttributeIndex
  - BasicBlock
  - BasicBlockCollection
  - Builder
  - CallConvention
  - CodeGenFileType
  - CodeGenOptLevel
  - CodeModel
  - Context
  - DIBuilder
  - DIFlags
  - DwarfTag
  - DwarfTypeEncoding
  - Function
  - FunctionCollection
  - FunctionPassManager
    - Runner
  - GenericValue
  - GlobalCollection
  - InstructionCollection
  - IntPredicate
  - JITCompiler
  - Linkage
  - MemoryBuffer
  - Module
  - ModuleFlag
  - ModulePassManager
  - ParameterCollection
  - PassManagerBuilder
  - PassRegistry
  - PhiTable
  - RealPredicate
  - RelocMode
  - Target
  - TargetData
  - TargetMachine
  - Type
    - Kind
  - Value
    - Kind
  - ValueMethods
  - VerifierFailureAction
- Logger
  - Formatter
  - Severity
- Markdown
  - HTMLRenderer
  - Parser
    - PrefixHeader
    - UnorderedList
  - Renderer
- Math
- Mutex
- NamedTuple
- Nil
- Number
  - Primitive
- OAuth
  - AccessToken
  - Consumer
  - Error
  - RequestToken
- OAuth2
  - AccessToken
    - Bearer
    - Mac
  - Client
  - Error
  - Session
- Object
- OpenSSL
  - Digest
    - Error
    - UnsupportedError
  - DigestBase
  - Error
  - HMAC
  - MD5
  - SHA1
  - SSL
    - Context
      - Client
      - Server
    - Error
    - ErrorType
    - Modes
    - Options
    - Socket
      - Client
      - Server
    - VerifyMode
    - X509VerifyFlags
- OptionParser
  - Exception
  - InvalidOption
  - MissingOption
- PartialComparable
- Pointer
  - Appender
- PrettyPrint
- Proc
- Process
  - Env
  - Status
  - Stdio
  - Tms
- Random
  - MT19937
- Range
- Readline
  - CompletionProc
  - KeyBindingProc
- Reference
- Reflect
- Regex
  - MatchData
  - Options
- SecureRandom
- Set
- Signal
- Slice
- Socket
  - Address
  - Addrinfo
  - Error
  - Family
  - IPAddress
  - Protocol
  - Server
  - Type
  - UNIXAddress
- Spec
  - Expectations
  - Methods
  - ObjectExtensions
- StaticArray
- String
  - Builder
  - RawConverter
- StringPool
- StringScanner
- Struct
- Symbol
- System
- TCPServer
- TCPSocket
- Tempfile
- Termios
  - AttributeSelection
  - BaudRate
  - ControlMode
  - InputMode
  - LineControl
  - LocalMode
  - OutputMode
- Time
  - DayOfWeek
  - EpochConverter
  - EpochMillisConverter
  - Format
    - Error
  - Kind
  - MonthSpan
  - Span
- Tuple
- TypeCastError
- UDPSocket
- UInt16
- UInt32
- UInt64
- UInt8
- Unicode
  - CaseOptions
- Union
- UNIXServer
- UNIXSocket
- URI
  - Error
- Value
- WeakRef
- XML
  - Attributes
  - AttributeType
  - Builder
  - Error
  - HTMLParserOptions
  - Namespace
  - Node
  - NodeSet
  - ParserOptions
  - Reader
  - SaveOptions
  - Type
  - XPathContext
- YAML
  - Any
  - Builder
  - Error
  - EventKind
  - ParseException
  - Parser
  - PullParser
  - Type
- Zip
  - CompressionMethod
  - Error
  - File
    - Entry
  - FileInfo
  - Reader
    - Entry
  - Writer
    - Entry
- Zlib
  - Error
  - Reader
  - Writer

# struct XML::Node

- XML::Node
- Struct
- Value
- Object

## Defined in:

## Constant Summary

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

## Class Method Summary

- .new(node : Pointer(LibXML::Attr))

  Creates a new node.

- .new(node : Pointer(LibXML::Doc))

  Creates a new node.

- .new(node : Pointer(LibXML::Node))

  Creates a new node.

## Instance Method Summary

- #==(other : Node)

  Compares with other.

- #[](attribute : String) : String

  Gets the attribute content for the attribute given by name.

- #[]=(name : String, value : String)

  Sets attribute of this node to value.

- #[]?(attribute : String) : String?

  Gets the attribute content for the attribute given by name.

- #attribute?

  Returns `true` if this is an attribute node.

- #attributes

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

- #cdata?

  Returns `true` if this is a `CDATA` section node.

- #children

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

- #comment?

  Returns `true` if 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)

  Deletes attribute given by name.

- #document

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

- #document?

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

- #element?

  Returns `true` if this is an Element node.

- #encoding

  Returns the encoding of this node's document.

- #errors

  Returns the list of `XML::Error` found when parsing this document.

- #first_element_child

  Returns the first child node of this node that is an element.

- #fragment?

  Returns `true` if this is a DocumentFragment.

- #hash

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

- #inner_text

  Returns the content for this Node.

- #inspect(io)

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

- #name

  Returns the name for this Node.

- #name=(name)

  Sets the name for this Node.

- #namespace

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

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

- #namespaces

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

- #next

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

- #next_element

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

- #next_sibling

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

- #object_id

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

- #parent

  Returns the parent node or `nil` if not found.

- #previous

  Returns the previous sibling node or `nil` if not found.

- #previous_element

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

- #previous_sibling

  Returns the previous sibling node or `nil` if not found.

- #processing_instruction?

  Returns `true` if this is a Processing Instruction node.

- #root

  Returns the root node for this document or `nil`.

- #text

  Same as `#content`.

- #text=(text)

  Same as `#content=`.

- #text?

  Returns `true` if this is a Text node.

- #to_s(io : IO)

  Serialize this Node as XML to io using default options.

- #to_unsafe : Pointer(LibXML::Node)

  Returns underlying `LibXML::Node*` instance.

- #to_xml(indent : Int = 2, indent_text = " ", options : SaveOptions = SaveOptions.xml_default)

  Serialize this Node as XML and return a `String` using 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

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

- #version

  Returns the version of this node's document.

- #xml?

  Returns `true` if 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 struct `Struct`

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

### Instance methods inherited from struct `Value`

==(other) ==, dup dup

### Instance methods inherited from class `Object`

!=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other) ===, =~(other) =~, class class, dup dup, hash hash, inspect(io : IO)
inspect inspect, itself itself, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, tap(&block) tap, to_json(io : IO)
to_json to_json, to_pretty_json(indent : String = " ")
to_pretty_json(io : IO, indent : String = " ") 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`

from_json(string_or_io, root : String) : self
from_json(string_or_io) : self from_json, from_yaml(string_or_io) : self from_yaml

## Class Method Detail

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

Creates a new node.

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

Creates a new node.

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

Creates a new node.

## Instance Method Detail

def ==(other : Node) #

Compares with other.

def [](attribute : String) : String #

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

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

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

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

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

def attribute? #

Returns `true` if this is an attribute node.

def attributes #

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

def cdata? #

Returns `true` if this is a `CDATA` section node.

def children #

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

def comment? #

Returns `true` if this is a comment node.

def content : String #

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

def content=(content) #

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

def delete(name : String) #

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

def document #

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

def document? #

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

def element? #

Returns `true` if this is an Element node.

def encoding #

Returns the encoding of this node's document.

def errors #

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

def first_element_child #

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

def fragment? #

Returns `true` if this is a DocumentFragment.

def hash #

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

def inner_text #

Returns the content for this Node.

def inspect(io) #

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

def name #

Returns the name for this Node.

def name=(name) #

Sets the name for this Node.

def namespace #

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

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`

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 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 next #

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

def next_element #

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

def next_sibling #

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

def object_id #

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

def parent #

Returns the parent node or `nil` if not found.

def previous #

Returns the previous sibling node or `nil` if not found.

def previous_element #

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

def previous_sibling #

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

def processing_instruction? #

Returns `true` if this is a Processing Instruction node.

def root #

Returns the root node for this document or `nil`.

def text #

Same as `#content`.

def text=(text) #

Same as `#content=`.

def text? #

Returns `true` if this is a Text node.

def to_s(io : IO) #

Serialize this Node as XML to io using default options.

See `#to_xml`.

def to_unsafe : Pointer(LibXML::Node) #

Returns underlying `LibXML::Node*` instance.

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.

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.

def type #

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

def version #

Returns the version of this node's document.

def xml? #

Returns `true` if this is an xml Document node.

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.

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

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) #

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

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

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

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

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

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

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

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

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

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

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