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¶
Methods¶
#attribute(prefix : String?, name : String, namespace_uri : String?, value) : Nil
¶
(prefix : String?, name : String, namespace_uri : String?, value) : Nil
Emits an attribute with namespace info and a value.
#attribute
¶
Emits the start of an attribute, invokes the block, and then emits the end of the attribute.
#attributes(attributes : Hash | NamedTuple)
¶
(attributes : Hash | NamedTuple)
Emits the given attributes with their values.
#cdata(text : String) : Nil
¶
(text : String) : Nil
Emits a CDATA
section. Escapes nested CDATA
end sequences.
#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.
#comment
¶
Emits the start of a comment, invokes the block and then emits the end of the comment.
#document(version = nil, encoding = nil
¶
(version = nil, encoding = nil
Emits the start of the document, invokes the block, and then emits the end of the document.
#dtd(name : String, pubid : String, sysid : String, subset : String? = nil) : Nil
¶
(name : String, pubid : String, sysid : String, subset : String? = nil) : Nil
Emits a DTD
.
#dtd(name : String, pubid : String, sysid : String, &) : Nil
¶
(name : String, pubid : String, sysid : String, &) : Nil
Emits the start of a DTD
, invokes the block
and then emits the end of the DTD
.
#element(__name__ : String
¶
(__name__ : String
Emits the start of an element with the given attributes, invokes the block and then emits the end of the element.
#element(prefix : String?, name : String, namespace_uri : String?, attributes : Hash | NamedTuple)
¶
(prefix : String?, name : String, namespace_uri : String?, attributes : Hash | NamedTuple)
Emits an element with namespace info with the given attributes.
#element(prefix : String?, name : String, namespace_uri : String?, **attributes)
¶
(prefix : String?, name : String, namespace_uri : String?, **attributes)
Emits an element with namespace info with the given attributes.
#element(name : String, attributes : Hash | NamedTuple)
¶
(name : String, attributes : Hash | NamedTuple)
Emits an element with the given attributes.
#element(__name__ : String, attributes : Hash | NamedTuple
¶
(__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.
#element(__prefix__ : String?, __name__ : String, __namespace_uri__ : String
¶
(__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.
#element(__prefix__ : String?, __name__ : String, __namespace_uri__ : String?, attributes : Hash | NamedTuple
¶
(__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.
#start_attribute(prefix : String?, name : String, namespace_uri : String?)
¶
(prefix : String?, name : String, namespace_uri : String?)
Emits the start of an attribute with namespace info.
#start_dtd(name : String, pubid : String, sysid : String) : Nil
¶
(name : String, pubid : String, sysid : String) : Nil
Emits the start of a DTD
.