W3cubDocs

/Crystal 0.31

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

Constructors

Instance Method Summary

Constructor Detail

def self.new(io : IO)Source

Creates a builder that writes to the given io.

Instance Method Detail

def attribute(name : String, value) : NilSource

Emits an attribute with a value.

def attribute(prefix : String?, name : String, namespace_uri : String?, value) : NilSource

Emits an attribute with namespace info and a value.

def attribute(*args, **nargs, &block)Source

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

def attributes(attributes : Hash | NamedTuple)Source

Emits the given attributes with their values.

def attributes(**attributes)Source

Emits the given attributes with their values.

def cdata(text : String) : NilSource

Emits a CDATA section.

def cdata(&block)Source

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

def comment(text : String) : NilSource

Emits a comment.

def comment(&block)Source

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

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

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

def dtd(name : String, pubid : String, sysid : String, subset : String? = nil) : NilSource

Emits a DTD.

def dtd(name : String, pubid : String, sysid : String, &block) : NilSource

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

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

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

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

Emits an element with namespace info with the given attributes.

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

Emits an element with namespace info with the given attributes.

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

Emits an element with the given attributes.

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

Emits an element with the given attributes.

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

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

def element(__prefix__ : String?, __name__ : String, __namespace_uri__ : String?, **attributes, &block)Source

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

def element(__prefix__ : String?, __name__ : String, __namespace_uri__ : String?, attributes : Hash | NamedTuple, &block)Source

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

def end_attribute : NilSource

Emits the end of an attribute.

def end_cdata : NilSource

Emits the end of a CDATA section.

def end_comment : NilSource

Emits the end of a comment.

def end_document : NilSource

Emits the end of a document.

def end_dtd : NilSource

Emits the end of a DTD.

def end_element : NilSource

Emits the end of an element.

def flushSource

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

def indent=(level : Int)Source

Sets the indent level (number of spaces).

def indent=(str : String)Source

Sets the indent string.

def namespace(prefix, uri)Source

Emits a namespace.

def quote_char=(char : Char)Source

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

def start_attribute(name : String) : NilSource

Emits the start of an attribute.

def start_attribute(prefix : String?, name : String, namespace_uri : String?)Source

Emits the start of an attribute with namespace info.

def start_cdata : NilSource

Emits the start of a CDATA section.

def start_comment : NilSource

Emits the start of a comment.

def start_document(version = nil, encoding = nil) : NilSource

Emits the start of the document.

def start_dtd(name : String, pubid : String, sysid : String) : NilSource

Emits the start of a DTD.

def start_element(name : String) : NilSource

Emits the start of an element.

def start_element(prefix : String?, name : String, namespace_uri : String?) : NilSource

Emits the start of an element with namespace info.

def text(content : String) : NilSource

Emits text content.

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

© 2012–2019 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.31.1/XML/Builder.html