Name of the element.
Optional, legacy; attributes for the element as an associative array mapping attribute names to their values.
An Element type, implicitly castable to string. Instances of Element can be safely placed
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>");
Create an XML element.
elemX builds the element with attributes and child content given as arguments. Their kind is distinguished by their type — child element should be passed as Element, attributes as Attribute and text content as string.
* You can pass the result of elemX to another elemX call to create child nodes: elemX!"parent"(elemX!"child"()). * Use attr to specify attributes: elemX!"element"(attr("key") = "value"). * Pass a string to specify text content: elemX!"text"("Hello").
elemX also provides the option to specify attributes from an associative array or source: elemX!"element"(["key": "value"]) or elemX!("element", key="value") but these are considered legacy and should be avoided in new code.