DOMEntity.pos

The position in the the original text where the entity starts.

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

Examples

1 import std.range.primitives : empty;
2 import dxml.parser : TextPos;
3 import dxml.util : stripIndent;
4 
5 auto xml = "<root>\n" ~
6            "    <foo>\n" ~
7            "        Foo and bar. Always foo and bar...\n" ~
8            "    </foo>\n" ~
9            "</root>";
10 
11 auto dom = parseDOM(xml);
12 assert(dom.type == EntityType.elementStart);
13 assert(dom.name.empty);
14 assert(dom.pos == TextPos(1, 1));
15 
16 auto root = dom.children[0];
17 assert(root.type == EntityType.elementStart);
18 assert(root.name == "root");
19 assert(root.pos == TextPos(1, 1));
20 
21 auto foo = root.children[0];
22 assert(foo.type == EntityType.elementStart);
23 assert(foo.name == "foo");
24 assert(foo.pos == TextPos(2, 5));
25 
26 auto text = foo.children[0];
27 assert(text.type == EntityType.text);
28 assert(text.text.stripIndent() ==
29        "Foo and bar. Always foo and bar...");
30 assert(text.pos == TextPos(2, 10));

See Also

Meta