1 import std.range.primitives : empty; 2 3 auto xml = "<root>\n" ~ 4 " <bar>\n" ~ 5 " <baz>\n" ~ 6 " <xyzzy/>\n" ~ 7 " </baz>\n" ~ 8 " <frobozz>\n" ~ 9 " <!-- comment -->\n" ~ 10 " It's magic!\n" ~ 11 " </frobozz>\n" ~ 12 " </bar>\n" ~ 13 " <foo></foo>\n" ~ 14 "</root>"; 15 16 auto dom = parseDOM(xml); 17 assert(dom.type == EntityType.elementStart); 18 assert(dom.name.empty); 19 assert(dom.path.empty); 20 21 auto root = dom.children[0]; 22 assert(root.type == EntityType.elementStart); 23 assert(root.name == "root"); 24 assert(root.path.empty); 25 26 auto bar = root.children[0]; 27 assert(bar.type == EntityType.elementStart); 28 assert(bar.name == "bar"); 29 assert(bar.path == ["root"]); 30 31 auto baz = bar.children[0]; 32 assert(baz.type == EntityType.elementStart); 33 assert(baz.name == "baz"); 34 assert(baz.path == ["root", "bar"]); 35 36 auto xyzzy = baz.children[0]; 37 assert(xyzzy.type == EntityType.elementEmpty); 38 assert(xyzzy.name == "xyzzy"); 39 assert(xyzzy.path == ["root", "bar", "baz"]); 40 41 auto frobozz = bar.children[1]; 42 assert(frobozz.type == EntityType.elementStart); 43 assert(frobozz.name == "frobozz"); 44 assert(frobozz.path == ["root", "bar"]); 45 46 auto comment = frobozz.children[0]; 47 assert(comment.type == EntityType.comment); 48 assert(comment.text == " comment "); 49 assert(comment.path == ["root", "bar", "frobozz"]); 50 51 auto text = frobozz.children[1]; 52 assert(text.type == EntityType.text); 53 assert(text.text == "\n It's magic!\n "); 54 assert(text.path == ["root", "bar", "frobozz"]); 55 56 auto foo = root.children[1]; 57 assert(foo.type == EntityType.elementStart); 58 assert(foo.name == "foo"); 59 assert(foo.path == ["root"]);
Gives the list of the names of the parent start tags of this DOMEntity.
The name of the current entity (if it has one) is not included in the path.
Note that if parseDOM were given an EntityRange, the path starts where the range started. So, it doesn't necessarily contain the entire path from the start of the XML document.