struct XML::Builder

Overview

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)

Defined in:

xml/builder.cr

Class Method Summary

Instance Method Summary

Instance methods inherited from struct Struct

==(other : self) : Bool ==, hash : Int32 hash, inspect(io : IO) : Nil inspect, pretty_print(pp) : Nil pretty_print, to_s(io) to_s

Instance methods inherited from struct Value

==(other) ==, dup dup

Instance methods inherited from class Object

!=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other)
===
, =~(other) =~, class class, dup dup, hash hash, inspect(io : IO)
inspect
inspect
, itself itself, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, tap(&block) tap, to_json(io : IO)
to_json
to_json
, to_pretty_json(indent : String = " ")
to_pretty_json(io : IO, indent : String = " ")
to_pretty_json
, to_s
to_s(io : IO)
to_s
, to_yaml(io : IO)
to_yaml
to_yaml
, try(&block) try

Class methods inherited from class Object

from_json(string_or_io, root : String) : self
from_json(string_or_io) : self
from_json
, from_yaml(string_or_io) : self from_yaml

Class Method Detail

def self.new(io : IO) #

Creates a builder that writes to the given io.


[View source]

Instance Method Detail

def attribute(name : String, value) : Nil #

Emits an attribute with a value.


[View source]
def attribute(prefix : String?, name : String, namespace_uri : String?, value) : Nil #

Emits an attribute with namespace info and a value.


[View source]
def attribute(*args, **nargs, &block) #

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


[View source]
def attributes(attributes : Hash | NamedTuple) #

Emits the given attributes with their values.


[View source]
def attributes #

Emits the given attributes with their values.


[View source]
def cdata(text : String) : Nil #

Emits a CDATA section.


[View source]
def cdata(&block) #

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


[View source]
def comment(text : String) : Nil #

Emits a comment.


[View source]
def comment(&block) #

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


[View source]
def document(version = nil, encoding = nil, &block) #

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


[View source]
def dtd(name : String, pubid : String, sysid : String, subset : String? = nil) : Nil #

Emits a DTD.


[View source]
def dtd(name : String, pubid : String, sysid : String, &block) : Nil #

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


[View source]
def element(__name__ : String, **attributes, &block) #

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


[View source]
def element(prefix : String?, name : String, namespace_uri : String?, attributes : Hash | NamedTuple) #

Emits an element with namespace info with the given attributes.


[View source]
def element(prefix : String?, name : String, namespace_uri : String?, **attributes) #

Emits an element with namespace info with the given attributes.


[View source]
def element(name : String, attributes : Hash | NamedTuple) #

Emits an element with the given attributes.


[View source]
def element(__name__ : String, **attributes) #

Emits an element with the given attributes.


[View source]
def element(__name__ : String, attributes : Hash | NamedTuple, &block) #

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


[View source]
def element(__prefix__ : String?, __name__ : String, __namespace_uri__ : String?, **attributes, &block) #

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]
def element(__prefix__ : String?, __name__ : String, __namespace_uri__ : String?, attributes : Hash | NamedTuple, &block) #

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]
def end_attribute : Nil #

Emits the end of an attribute.


[View source]
def end_cdata : Nil #

Emits the end of a CDATA section.


[View source]
def end_comment : Nil #

Emits the end of a comment.


[View source]
def end_document : Nil #

Emits the end of a document.


[View source]
def end_dtd : Nil #

Emits the end of a DTD.


[View source]
def end_element : Nil #

Emits the end of an element.


[View source]
def flush #

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


[View source]
def indent=(level : Int) #

Sets the indent level (number of spaces).


[View source]
def indent=(str : String) #

Sets the indent string.


[View source]
def namespace(prefix, uri) #

Emits a namespace.


[View source]
def quote_char=(char : Char) #

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


[View source]
def start_attribute(name : String) : Nil #

Emits the start of an attribute.


[View source]
def start_attribute(prefix : String?, name : String, namespace_uri : String?) #

Emits the start of an attribute with namespace info.


[View source]
def start_cdata : Nil #

Emits the start of a CDATA section.


[View source]
def start_comment : Nil #

Emits the start of a comment.


[View source]
def start_document(version = nil, encoding = nil) : Nil #

Emits the start of the document.


[View source]
def start_dtd(name : String, pubid : String, sysid : String) : Nil #

Emits the start of a DTD.


[View source]
def start_element(name : String) : Nil #

Emits the start of an element.


[View source]
def start_element(prefix : String?, name : String, namespace_uri : String?) : Nil #

Emits the start of an element with namespace info.


[View source]
def text(content : String) : Nil #

Emits text content.

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


[View source]