elemX

Create an XML element.

  1. Element elemX(Ts content)
    elemX
    (
    string name
    string[string] attributes
    Ts...
    )
    ()
  2. Element elemX(string[string] attributes, T content)
  3. Element elemX(T content)

Parameters

name

Name of the element.

attributes

Attributes for the element as an associative array mapping attribute names to their values.

content Ts

Attributes (via Attribute and attr), children and text of the element.

Return Value

Type: Element

a Element type, implictly castable to string.

Examples

enum xml = elemX!"xml"(
    elemX!"heading"("This is my sample document!"),
    elemX!("spacing /", q{ height="1em" }),
    elemX!"spacing /"(["height": "1em"]),
    elemX!"empty",
    elemX!"br",
    elemX!"container"
        .addX!"paragraph"("Foo")
        .addX!"paragraph"("Bar"),
);

assert(xml == "<xml>" ~ (
        "<heading>This is my sample document!</heading>"
        ~ `<spacing height="1em"/>`
        ~ `<spacing height="1em"/>`
        ~ `<empty></empty>`
        ~ `<br></br>`
        ~ "<container>" ~ (
            "<paragraph>Foo</paragraph>"
            ~ "<paragraph>Bar</paragraph>"
        ) ~ "</container>"
    ) ~ "</xml>");

Meta