builder.xml.Element
class pub Element
A named XML element.
Fields
name
let pub @name: String
The name of this element.
attributes
let pub @attributes: Map[String, String]
The attributes of this element.
nodes
let pub @nodes: Array[Node]
The child nodes of this element.
Static methods
new
Show source codeHide source code
fn pub static new(name: String) -> Element {
Element(name: name, attributes: Map.new, nodes: [], self_closing: false)
}
fn pub static new(name: String) -> Element
Returns a new element with the given name.
Examples
import builder.xml.Element
Element.new('person')
Instance methods
attr
Show source codeHide source code
fn pub mut attr(name: String, value: String) -> mut Element {
@attributes.set(name, value)
self
}
fn pub mut attr(name: String, value: String) -> mut Element
Adds an attribute to this element.
Examples
import builder.xml.Element
Element.new('user').attr('verified', 'true')
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 Element
Adds a child element with the given name.
Examples
import builder.xml.Element
Element.new('person').element('name')
self_closing
Show source codeHide source code
fn pub mut self_closing -> mut Element {
@self_closing = true
self
}
fn pub mut self_closing -> mut Element
Marks this element as being a self-closing element.
Examples
import builder.xml.Element
Element.new('link').self_closing
self_closing?
Show source codeHide source code
fn pub self_closing? -> Bool {
@self_closing
}
fn pub self_closing? -> Bool
Returns true
if this element is a self-closing element.
Examples
import builder.xml.Element
let el = Element.new('link')
el.self_closing
el.self_closing? # => true
text
Show source codeHide source code
fn pub mut text(text: String) -> mut Element {
@nodes.push(Node.Text(text))
self
}
fn pub mut text(text: String) -> mut Element
Adds a text node to this element.
Examples
import builder.xml.Element
Element.new('p').text('Hello!')
with
Show source codeHide source code
fn pub mut with(func: fn (mut Element)) -> mut Element {
func.call(self)
self
}
fn pub mut with(func: fn (mut Element)) -> mut Element
Calls the supplied closure, passing it a mutable reference to this element.
Examples
import builder.xml.Element
Element.new('person').with fn (person) {
person.element('name')
}