Skip to content

class XML::Builder
inherits Reference

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)

Class methods

.new(io : IO)

Creates a builder that writes to the given io.

View source

Methods

#attribute(name : String, value) : Nil

Emits an attribute with a value.

View source

#attribute(prefix : String?, name : String, namespace_uri : String?, value) : Nil

Emits an attribute with namespace info and a value.

View source

#attribute

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

View source

#attributes(attributes : Hash | NamedTuple)

Emits the given attributes with their values.

View source

#attributes(**attributes)

Emits the given attributes with their values.

View source

#cdata(text : String) : Nil

Emits a CDATA section. Escapes nested CDATA end sequences.

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

View source

#comment(text : String) : Nil

Emits a comment.

View source

#comment

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

View source

#document(version = nil, encoding = nil

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

View source

#dtd(name : String, pubid : String, sysid : String, subset : String? = nil) : Nil

Emits a DTD.

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

View source

#element(__name__ : String

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

View source

#element(prefix : String?, name : String, namespace_uri : String?, attributes : Hash | NamedTuple)

Emits an element with namespace info with the given attributes.

View source

#element(prefix : String?, name : String, namespace_uri : String?, **attributes)

Emits an element with namespace info with the given attributes.

View source

#element(name : String, attributes : Hash | NamedTuple)

Emits an element with the given attributes.

View source

#element(__name__ : String, **attributes)

Emits an element with the given attributes.

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

View source

#element(__prefix__ : String?, __name__ : String, __namespace_uri__ : String

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

View source

#element(__prefix__ : String?, __name__ : String, __namespace_uri__ : String?, 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.

View source

#end_attribute : Nil

Emits the end of an attribute.

View source

#end_cdata : Nil

Emits the end of a CDATA section.

View source

#end_comment : Nil

Emits the end of a comment.

View source

#end_document : Nil

Emits the end of a document.

View source

#end_dtd : Nil

Emits the end of a DTD.

View source

#end_element : Nil

Emits the end of an element.

View source

#flush

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

View source

#indent=(level : Int)

Sets the indent level (number of spaces).

View source

#indent=(str : String)

Sets the indent string.

View source

#namespace(prefix, uri)

Emits a namespace.

View source

#quote_char=(char : Char)

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

View source

#start_attribute(name : String) : Nil

Emits the start of an attribute.

View source

#start_attribute(prefix : String?, name : String, namespace_uri : String?)

Emits the start of an attribute with namespace info.

View source

#start_cdata : Nil

Emits the start of a CDATA section.

View source

#start_comment : Nil

Emits the start of a comment.

View source

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

Emits the start of the document.

View source

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

Emits the start of a DTD.

View source

#start_element(name : String) : Nil

Emits the start of an element.

View source

#start_element(prefix : String?, name : String, namespace_uri : String?) : Nil

Emits the start of an element with namespace info.

View source

#text(content : String) : Nil

Emits text content.

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

View source