EntityRange.text

Returns the textual value of this Entity.

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 EntityRange(Config cfg, R)
@property
text
(
)
if (
isForwardRange!R &&
isSomeChar!(ElementType!R)
)

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 range = parseXML(xml);
15 
16 // "<?instructionName?>\n" ~
17 assert(range.front.type == EntityType.pi);
18 assert(range.front.name == "instructionName");
19 assert(range.front.text.empty);
20 
21 // "<?foo here is something to say?>\n" ~
22 range.popFront();
23 assert(range.front.type == EntityType.pi);
24 assert(range.front.name == "foo");
25 assert(range.front.text == "here is something to say");
26 
27 // "<root>\n" ~
28 range.popFront();
29 assert(range.front.type == EntityType.elementStart);
30 
31 // "    <![CDATA[ Yay! random text >> << ]]>\n" ~
32 range.popFront();
33 assert(range.front.type == EntityType.cdata);
34 assert(range.front.text == " Yay! random text >> << ");
35 
36 // "    <!-- some random comment -->\n" ~
37 range.popFront();
38 assert(range.front.type == EntityType.comment);
39 assert(range.front.text == " some random comment ");
40 
41 // "    <p>something here</p>\n" ~
42 range.popFront();
43 assert(range.front.type == EntityType.elementStart);
44 assert(range.front.name == "p");
45 
46 range.popFront();
47 assert(range.front.type == EntityType.text);
48 assert(range.front.text == "something here");
49 
50 range.popFront();
51 assert(range.front.type == EntityType.elementEnd);
52 assert(range.front.name == "p");
53 
54 // "    <p>\n" ~
55 // "       something else\n" ~
56 // "       here</p>\n" ~
57 range.popFront();
58 assert(range.front.type == EntityType.elementStart);
59 
60 range.popFront();
61 assert(range.front.type == EntityType.text);
62 assert(range.front.text == "\n       something else\n       here");
63 
64 range.popFront();
65 assert(range.front.type == EntityType.elementEnd);
66 
67 // "</root>"
68 range.popFront();
69 assert(range.front.type == EntityType.elementEnd);
70 
71 range.popFront();
72 assert(range.empty);

See Also

Meta