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
type
@safe const pure nothrow @nogc
(
)

Examples

1 import std.range.primitives;
2 
3 auto xml = "<root>\n" ~
4            "    <!--no comment-->\n" ~
5            "    <![CDATA[cdata run]]>\n" ~
6            "    <text>I am text!</text>\n" ~
7            "    <empty/>\n" ~
8            "    <?pi?>\n" ~
9            "</root>";
10 
11 auto dom = parseDOM(xml);
12 assert(dom.type == EntityType.elementStart);
13 assert(dom.name.empty);
14 assert(dom.children.length == 1);
15 
16 auto root = dom.children[0];
17 assert(root.type == EntityType.elementStart);
18 assert(root.name == "root");
19 assert(root.children.length == 5);
20 
21 assert(root.children[0].type == EntityType.comment);
22 assert(root.children[0].text == "no comment");
23 
24 assert(root.children[1].type == EntityType.cdata);
25 assert(root.children[1].text == "cdata run");
26 
27 auto textTag = root.children[2];
28 assert(textTag.type == EntityType.elementStart);
29 assert(textTag.name == "text");
30 assert(textTag.children.length == 1);
31 
32 assert(textTag.children[0].type == EntityType.text);
33 assert(textTag.children[0].text == "I am text!");
34 
35 assert(root.children[3].type == EntityType.elementEmpty);
36 assert(root.children[3].name == "empty");
37 
38 assert(root.children[4].type == EntityType.pi);
39 assert(root.children[4].name == "pi");

Meta