DOMEntity.text

Returns the textual value of this DOMEntity.

In the case of EntityType.pi, this is the text that follows the name, whereas in the other cases, the text is the entire contents of the entity (save for the delimeters on the ends if that entity has them).

Supported EntityTypes:
cdata
comment
pi
_text
struct DOMEntity(R)
@property
text
()

Examples

1 import std.range.primitives : empty;
2 
3 auto xml = "<?xml version='1.0'?>\n" ~
4            "<?instructionName?>\n" ~
5            "<?foo here is something to say?>\n" ~
6            "<root>\n" ~
7            "    <![CDATA[ Yay! random text >> << ]]>\n" ~
8            "    <!-- some random comment -->\n" ~
9            "    <p>something here</p>\n" ~
10            "    <p>\n" ~
11            "       something else\n" ~
12            "       here</p>\n" ~
13            "</root>";
14 auto dom = parseDOM(xml);
15 
16 // "<?instructionName?>\n" ~
17 auto pi1 = dom.children[0];
18 assert(pi1.type == EntityType.pi);
19 assert(pi1.name == "instructionName");
20 assert(pi1.text.empty);
21 
22 // "<?foo here is something to say?>\n" ~
23 auto pi2 = dom.children[1];
24 assert(pi2.type == EntityType.pi);
25 assert(pi2.name == "foo");
26 assert(pi2.text == "here is something to say");
27 
28 // "<root>\n" ~
29 auto root = dom.children[2];
30 assert(root.type == EntityType.elementStart);
31 
32 // "    <![CDATA[ Yay! random text >> << ]]>\n" ~
33 auto cdata = root.children[0];
34 assert(cdata.type == EntityType.cdata);
35 assert(cdata.text == " Yay! random text >> << ");
36 
37 // "    <!-- some random comment -->\n" ~
38 auto comment = root.children[1];
39 assert(comment.type == EntityType.comment);
40 assert(comment.text == " some random comment ");
41 
42 // "    <p>something here</p>\n" ~
43 auto p1 = root.children[2];
44 assert(p1.type == EntityType.elementStart);
45 assert(p1.name == "p");
46 
47 assert(p1.children[0].type == EntityType.text);
48 assert(p1.children[0].text == "something here");
49 
50 // "    <p>\n" ~
51 // "       something else\n" ~
52 // "       here</p>\n" ~
53 auto p2 = root.children[3];
54 assert(p2.type == EntityType.elementStart);
55 
56 assert(p2.children[0].type == EntityType.text);
57 assert(p2.children[0].text == "\n       something else\n       here");

See Also

Meta