Search results

There are no results.

std.xml.Element

type pub inline Element

An XML element.

Instance methods

attr

Show source code
Hide source code
fn pub inline move attr(name: String, value: String) -> Self {
  @xml.add(' ')
  @xml.attr(name, value)
  self
}
fn pub inline move attr(name: String, value: String) -> Element

Adds an attribute to self.

Examples

import std.xml (Xml)

let doc = Xml.empty

doc.element('foo').attr('key', 'value').close
doc.to_string # => '<foo key="value"></foo>'

close

Show source code
Hide source code
fn pub inline move close {
  @open = false
  add_closing_tag
}
fn pub inline move close

Adds the closing tag for self and consumes it.

This method should be called when a Element is created and other moving methods such as Element.text aren't used.

Examples

import std.xml (Xml)

let doc = Xml.empty

doc.element('foo').close
doc.to_string # => '<foo></foo>'

text

Show source code
Hide source code
fn pub inline move text[B: Bytes, T: ToSlice[B]](value: ref T) {
  @open = false
  @xml.inner_text(@name, value)
}
fn pub inline move text[B: Bytes, T: ToSlice[B]](value: ref T)

Sets the contents of self to the given text, then closes self.

Examples

import std.xml (Xml)

let doc = Xml.empty

doc.element('foo').text('hello & world')
doc.to_string # => '<foo>hello &amp; world</foo>'

then

Show source code
Hide source code
fn pub inline move then(body: fn (mut Xml)) {
  @open = false
  @xml.enter(@name, body)
}
fn pub inline move then(body: fn (mut Xml))

Closes the opening tag of self, calls the supplied closure then closes self.

This method may be used to "enter" or "descend" into an element.

Examples

import std.xml (Xml)

let doc = Xml.empty

doc.element('foo').then(fn (foo) { foo.element('bar').text('hello') })
doc.to_string # => '<foo><bar>hello</bar></foo>'

value

Show source code
Hide source code
fn pub inline move value[B: Bytes](value: ref B) {
  @open = false
  @xml.add('>')
  @xml.add(value)
  @xml.closing_tag(@name)
}
fn pub inline move value[B: Bytes](value: ref B)

Sets the contents of self to the given literal value, then closes self.

Unlike Element.text the given value is not escaped.

Examples

import std.xml (Xml)

let doc = Xml.empty

doc.element('foo').value('hello & world')
doc.to_string # => '<foo>hello & world</foo>'

Implemented traits

std.drop.

Drop

impl Drop for Element