builder.xml.Document
type pub DocumentAn XML document.
Fields
nodes
let pub @nodes: Array[Node]All top-level nodes in this document.
Static methods
new
Show source codeHide source code
fn pub static new -> Document {
Document([])
}fn pub static new -> DocumentReturns a new empty document.
with
Show source codeHide source code
fn pub static with(func: fn (mut Document)) -> Document {
let doc = new
func.call(doc)
doc
}fn pub static with(func: fn (mut Document)) -> DocumentCreates a document and passes a mutable reference to the closure, returning the document afterwards.
Examples
import builder.xml.Document
Document.with fn (doc) {
doc.element('person').with fn (person) {
person.element('name')
}
}
Instance methods
element
Show source codeHide source code
fn pub mut element(name: String) -> mut Element {
let el = Element.new(name)
let ret = mut el
@nodes.push(Node.Element(el))
ret
}fn pub mut element(name: String) -> mut ElementAdds an element with the given name this document.
Examples
import builder.xml.Document
Document.new.element('foo')
to_pretty_string
Show source codeHide source code
fn pub to_pretty_string -> String {
Generator.new(indent: ' ').generate(self)
}fn pub to_pretty_string -> StringReturns an indented String containing the XML representation of self.
This method uses two spaces for indentation. If you want to customize the
indentation, use the Generator type directly instead.
Examples
import builder.xml.Document
let doc = Document.new
doc.element('person')
doc.to_pretty_string # => "<person>\n</person>"
to_string
Show source codeHide source code
fn pub to_string -> String {
Generator.new(indent: '').generate(self)
}fn pub to_string -> StringReturns a String containing the XML representation of self.
Examples
import builder.xml.Document
let doc = Document.new
doc.element('person')
doc.to_string # => '<person></person>'
Implemented traits
ToString
impl ToString for Document