class

Mica::XML::Document

Inherits Reference < Object

A parsed XML document.

Nodes live in an arena owned by the document: fixed-size records in pages plus a chunked heap for names' values and text. Mica::XML::Node is a small struct (document + index) pointing into it, so a large document costs a few allocations instead of one object per node, and the garbage collector never scans node records (they hold no pointers).

A document answers the Mica::XML::Node API for its document node:

document = Mica::XML.parse(%(<feed><title>News</title></feed>))
document.root.try(&.name)                # => "feed"
document.xpath_string("string(//title)") # => "News"

Constants

DEFAULT_EDIT_BUDGET = Core::WorkBudget.new(operations_per_unit: 64, base_operations: 1000000)

The default budget for edits: the same rate as parsing, without a deadline (edits are calls the application makes one at a time).

Constructors

parse(source : String | Bytes | IO, options : ParserOptions = ParserOptions.default, meter : Core::WorkMeter | Nil = nil) : Document

Parses source into a document. See Mica::XML.parse.

Source

Instance methods

children(*args, **options)
Source
children(*args, **options, &)
Source
content(*args, **options)
Source
content(*args, **options, &)
Source
document?(*args, **options)
Source
document?(*args, **options, &)
Source
edit_budget

The work budget edits run under (see edit_meter).

Source
edit_budget=(budget : Core::WorkBudget) : Core::WorkBudget

Sets the edit budget. The next edit starts a fresh meter on it.

Source
edit_meter

Returns the meter that edits through Node (setting, renaming and removing attributes, names and content) are charged to. Its units are the document's nodes, name bytes and value bytes when it starts, plus one per edit call and the bytes each call is given (names, values, text), so the work of any sequence of edits stays linear in the document and the edits' input; a sequence that would do more stops with a Mica::WorkBudgetExceededError. Created on the first edit.

Source
encoding

Returns the encoding the document was read from.

Source
first_element_child(*args, **options)
Source
first_element_child(*args, **options, &)
Source
inner_text(*args, **options)
Source
inner_text(*args, **options, &)
Source
inspect(io : IO) : Nil

Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
Source
internal_subset

Returns the raw internal DTD subset, if any.

Source
name(*args, **options)
Source
name(*args, **options, &)
Source
namespace_aware?

True when the document was parsed with Namespaces in XML enforced (ParserOptions#namespace_aware). Edits follow the same rules.

Source
node

Returns the document node.

Source
node_count

Returns the number of node records, including attributes and unlinked nodes.

Source
parse_operations

Returns the operations the parse that built this document charged (reading and building together).

Source
public_id

Returns the DOCTYPE public identifier, if any.

Source
renew_edit_meter(budget : Core::WorkBudget = @edit_budget) : Core::WorkMeter

Replaces the edit meter with a fresh one for budget, for documents that are edited in rounds over a long life.

Source
root(*args, **options)
Source
root(*args, **options, &)
Source
standalone?

Returns true when the declaration says standalone="yes".

Source
system_id

Returns the DOCTYPE system identifier, if any. It was never fetched.

Source
text(*args, **options)
Source
text(*args, **options, &)
Source
to_s(io : IO) : Nil

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Source
to_xml(*args, **options)
Source
to_xml(*args, **options, &)
Source
type(*args, **options)
Source
type(*args, **options, &)
Source
version

Returns the XML version from the declaration ("1.0" when absent).

Source
xml?(*args, **options)
Source
xml?(*args, **options, &)
Source
xpath(*args, **options)
Source
xpath(*args, **options, &)
Source
xpath_bool(*args, **options)
Source
xpath_bool(*args, **options, &)
Source
xpath_float(*args, **options)
Source
xpath_float(*args, **options, &)
Source
xpath_node(*args, **options)
Source
xpath_node(*args, **options, &)
Source
xpath_nodes(*args, **options)
Source
xpath_nodes(*args, **options, &)
Source
xpath_string(*args, **options)
Source
xpath_string(*args, **options, &)
Source