class

XML::Builder

Inherits Reference / Object

An XML builder generates valid XML.

An XML::Error is raised if attempting to generate an invalid XML (for example, if invoking end_element without a matching start_element, or trying to use a non-string value as an object's field name)

Constructors

new(io : IO)

Creates a builder that writes to the given io.

Source

Instance methods

attribute(*args, **nargs, &)

Emits the start of an attribute, invokes the block, and then emits the end of the attribute.

Source
attribute(prefix : String | Nil, name : String, namespace_uri : String | Nil, value) : Nil

Emits an attribute with namespace info and a value.

Source
attribute(name : String, value) : Nil

Emits an attribute with a value.

Source
attributes(attributes : Hash | NamedTuple) : Nil

Emits the given attributes with their values.

Source
attributes

Emits the given attributes with their values.

Source
cdata

Emits the start of a CDATA section, invokes the block and then emits the end of the CDATA section.

NOTE: CDATA end sequences written within the block need to be escaped manually.

Source
cdata(text : String) : Nil

Emits a CDATA section. Escapes nested CDATA end sequences.

Source
comment

Emits the start of a comment, invokes the block and then emits the end of the comment.

Source
comment(text : String) : Nil

Emits a comment.

Source
document(version = nil, encoding = nil, &)

Emits the start of the document, invokes the block, and then emits the end of the document.

Source
dtd(name : String, pubid : String, sysid : String, &) : Nil

Emits the start of a DTD, invokes the block and then emits the end of the DTD.

Source
dtd(name : String, pubid : String, sysid : String, subset : String | Nil = nil) : Nil

Emits a DTD.

Source
element(__prefix__ : String | Nil, __name__ : String, __namespace_uri__ : String | Nil, attributes : Hash | NamedTuple, &)

Emits the start of an element with namespace info with the given attributes, invokes the block and then emits the end of the element.

Source
element(__prefix__ : String | Nil, __name__ : String, __namespace_uri__ : String | Nil, **attributes, &)

Emits the start of an element with namespace info with the given attributes, invokes the block and then emits the end of the element.

Source
element(__name__ : String, attributes : Hash | NamedTuple, &)

Emits the start of an element with the given attributes, invokes the block and then emits the end of the element.

Source
element(__name__ : String, **attributes, &)

Emits the start of an element with the given attributes, invokes the block and then emits the end of the element.

Source
element(prefix : String | Nil, name : String, namespace_uri : String | Nil, attributes : Hash | NamedTuple) : Nil

Emits an element with namespace info with the given attributes.

Source
element(prefix : String | Nil, name : String, namespace_uri : String | Nil, **attributes) : Nil

Emits an element with namespace info with the given attributes.

Source
element(name : String, attributes : Hash | NamedTuple) : Nil

Emits an element with the given attributes.

Source
element(__name__ : String, **attributes)

Emits an element with the given attributes.

Source
end_attribute

Emits the end of an attribute.

Source
end_cdata

Emits the end of a CDATA section.

Source
end_comment

Emits the end of a comment.

Source
end_document

Emits the end of a document.

Source
end_dtd

Emits the end of a DTD.

Source
end_element

Emits the end of an element.

Source
flush

Forces content written to this writer to be flushed to this writer's IO.

Source
indent=(str : String)

Sets the indent string.

Source
indent=(level : Int)

Sets the indent level (number of spaces).

Source
namespace(prefix, uri) : Nil

Emits a namespace.

Source
quote_char=(char : Char)

Sets the quote char to use, either ' or ".

Source
start_attribute(prefix : String | Nil, name : String, namespace_uri : String | Nil)

Emits the start of an attribute with namespace info.

Source
start_attribute(name : String) : Nil

Emits the start of an attribute.

Source
start_cdata

Emits the start of a CDATA section.

Source
start_comment

Emits the start of a comment.

Source
start_document(version = nil, encoding = nil) : Nil

Emits the start of the document.

Source
start_dtd(name : String, pubid : String, sysid : String) : Nil

Emits the start of a DTD.

Source
start_element(prefix : String | Nil, name : String, namespace_uri : String | Nil) : Nil

Emits the start of an element with namespace info.

Source
start_element(name : String) : Nil

Emits the start of an element.

Source
text(content : String) : Nil

Emits text content.

Text content can happen inside of an element, attribute value, cdata, dtd, etc.

Source