Mica::XML::Builder
Writes XML to an IO, escaping text and attribute values and checking
names and characters so the output is always well-formed. The API
mirrors stdlib XML::Builder.
string = Mica::XML.build(indent: 2) do |xml|
xml.element("feed", lang: "en") do
xml.element("title") { xml.text "Tom & Jerry" }
end
end
string # => "<?xml version=\"1.0\"?>\n<feed lang=\"en\">\n <title>Tom & Jerry</title>\n</feed>\n"
Misuse (an attribute after content, an end without a start, an invalid
name or character) raises Mica::XML::BuilderError.
Constants
Indentation stops growing past this depth, so indented output stays linear in the number of nodes.
Constructors
Instance methods
Writes attribute prefix:name in namespace_uri.
Writes text as a comment. Raises when it contains -- or ends
with -.
Writes a whole document: the declaration, the block's content and the final newline.
Writes a DOCTYPE declaration with an optional raw internal subset.
The subset is parsed first under the default work budget. Raises
BuilderError when it is malformed, and Mica::LimitExceededError
(including Mica::WorkBudgetExceededError) when checking it exceeds a
limit.
Writes a DOCTYPE declaration around the block.
Writes element prefix:name in namespace_uri around the block.
Writes element name with attributes around the block's content.
Writes element name with attributes around the block's content.
Writes an empty element prefix:name in namespace_uri.
Writes an empty element name with attributes.
Declares namespace uri for prefix (nil for the default namespace) on the open start tag.
Opens attribute name; write its value with text, then call
end_attribute.
Writes the XML declaration.
Opens a DOCTYPE declaration.
Opens element prefix:name, declaring namespace_uri for the prefix when it is not already in scope.