Search results

There are no results.

builder.xml.Document

class pub Document

An XML document.

Fields

nodes

let pub @nodes: Array[Node]

All top-level nodes in this document.

Static methods

new

Show source code
Hide source code
fn pub static new -> Document {
  Document([])
}
fn pub static new -> Document

Returns a new empty document.

with

Show source code
Hide 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)) -> Document

Creates 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 code
Hide 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 an element with the given name this document.

Examples

import builder.xml.Document

Document.new.element('foo')

to_pretty_string

Show source code
Hide source code
fn pub to_pretty_string -> String {
  Generator.new(indent: '  ').generate(self)
}
fn pub to_pretty_string -> String

Returns 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 code
Hide source code
fn pub to_string -> String {
  Generator.new(indent: '').generate(self)
}
fn pub to_string -> String

Returns 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

std.string.

ToString

impl ToString for Document