elemX

Create an XML element.

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

Parameters

name

Name of the element.

attrHTML

Unsanitized attributes to insert at compile-time.

attributes string[string]

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

content T

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