SimpleXML

XML documents. The tradeoff with such a scheme is that copying

More...

Constructors

this
this(uint nodes)

XML documents. The tradeoff with such a scheme is that copying

this
this(T[] xml)

Constructs a SimpleXML instance and parses the given content.

Members

Aliases

opCat
alias opCat = add
opCatAssign
alias opCatAssign = add

Functions

add
Node add(T[] name, T[] value)

Adds a new element to the root element of the document.

add
Node add(Element element)

Adds a new element to the root element of the document.

add
Node add(Attribute attribute)

Adds the given attribute to the root element of the document.

header
SimpleXML header(T[] encoding)

Prepend an XML header to the document tree.

opApply
int opApply(int delegate(ref Node) dg)

Iterates over the children of the root node

opIndex
Node opIndex(T[] name)

Returns the first child element of the root element, which matches the given name.

opIndexAssign
void opIndexAssign(T2 value, T[] name)

Finds the first child element of the root element with the given name and sets it's value to the given value. If the element could not be found it's created and the give value is set.

toString
char[] toString()

Returns a string representation of the document. It will return the whole tree as a string.

Structs

Attribute
struct Attribute

This is a name-value pair representing an attribute

Element
struct Element

This is a name-value pair representing an element

Node
struct Node

This struct represents a node in the tree

Variables

attribute
Node.AttributeProxy attribute;

This is an attribute proxy allowing to perform attribute operations on all the attributes in the root element of this document.

Detailed Description

Implements an easy to use interface on top of a DOM Document.

Parse example:

auto doc = new SimpleXML!(char)(content);
Stdout(doc).newline;

API example:

auto doc = new SimpleXML!(char);

// attach an xml header
doc.header;

// attach an element with some attributes, plus
// a child element with an attached data value
doc ~ "element"
	~ doc.Attribute("attrib1", "value")
	~ doc.Attribute("attrib2")
	~ doc.Element("child", "value");

// attach a single child element to the root element
// and a single attribute to the root element
doc ~= "element2";
doc.attribute ~= "attri3";

X-Path example:

auto doc = new SimpleXML!(char);

// attach an xml header
doc.header;

// attach an element with some attributes, plus
// a child element with an attached data value
doc ~ "element"
	~ doc.Attribute("attrib1", "value")
	~ doc.Attribute("attrib2")
	~ doc.Element("child", "value");

// select named-element
auto set = doc["child"];

// select the first attribute named "
// attrib2" in the root element
auto att = doc.attribute("attrib2");

// get the value of the first attribute
// named attrib1 in the root element
char[] value = doc.attribute["attrib1"];

Meta