DOMEntity.type

The EntityType for this DOMEntity.

The type can never be EntityType.elementEnd, because the end of children already indicates where the contents of the start tag end.

type determines which properties of the DOMEntity can be used, and it can determine whether functions which a DOMEntity is passed to are allowed to be called. Each function lists which EntityTypes are allowed, and it is an error to call them with any other EntityType.

struct DOMEntity(R)
@property @safe const pure nothrow @nogc
type
()

Examples

import std.range.primitives;

auto xml = "<root>\n" ~
           "    <!--no comment-->\n" ~
           "    <![CDATA[cdata run]]>\n" ~
           "    <text>I am text!</text>\n" ~
           "    <empty/>\n" ~
           "    <?pi?>\n" ~
           "</root>";

auto dom = parseDOM(xml);
assert(dom.type == EntityType.elementStart);
assert(dom.name.empty);
assert(dom.children.length == 1);

auto root = dom.children[0];
assert(root.type == EntityType.elementStart);
assert(root.name == "root");
assert(root.children.length == 5);

assert(root.children[0].type == EntityType.comment);
assert(root.children[0].text == "no comment");

assert(root.children[1].type == EntityType.cdata);
assert(root.children[1].text == "cdata run");

auto textTag = root.children[2];
assert(textTag.type == EntityType.elementStart);
assert(textTag.name == "text");
assert(textTag.children.length == 1);

assert(textTag.children[0].type == EntityType.text);
assert(textTag.children[0].text == "I am text!");

assert(root.children[3].type == EntityType.elementEmpty);
assert(root.children[3].name == "empty");

assert(root.children[4].type == EntityType.pi);
assert(root.children[4].name == "pi");

Meta