dxml.dom

This implements a DOM for representing an XML 1.0 document. parseDOM uses an dxml.parser.EntityRange to parse the document, and DOMEntity recursively represents the DOM tree.

See the documentation for dxml.parser and dxml.parser.EntityRange for details on the parser and its configuration options.

For convenience, dxml.parser.EntityType and dxml.parser.simpleXML are publicly imported by this module, since EntityType is required to correctly use DOMEntity, and simpleXML is highly likely to be used when calling parseDOM.

Public Imports

dxml.parser
public import dxml.parser : EntityType, simpleXML;

Members

Functions

parseDOM
DOMEntity!(ER.Input) parseDOM(ref ER range)
DOMEntity!R parseDOM(R range)

Represents an entity in an XML document as a DOM tree.

Structs

DOMEntity
struct DOMEntity(R)

Represents an entity in an XML document as a DOM tree.

Examples

1 import std.range.primitives : empty;
2 
3 auto xml = "<!-- comment -->\n" ~
4            "<root>\n" ~
5            "    <foo>some text<whatever/></foo>\n" ~
6            "    <bar/>\n" ~
7            "    <baz></baz>\n" ~
8            "</root>";
9 {
10     auto dom = parseDOM(xml);
11     assert(dom.type == EntityType.elementStart);
12     assert(dom.name.empty);
13     assert(dom.children.length == 2);
14 
15     assert(dom.children[0].type == EntityType.comment);
16     assert(dom.children[0].text == " comment ");
17 
18     auto root = dom.children[1];
19     assert(root.type == EntityType.elementStart);
20     assert(root.name == "root");
21     assert(root.children.length == 3);
22 
23     auto foo = root.children[0];
24     assert(foo.type == EntityType.elementStart);
25     assert(foo.name == "foo");
26     assert(foo.children.length == 2);
27 
28     assert(foo.children[0].type == EntityType.text);
29     assert(foo.children[0].text == "some text");
30 
31     assert(foo.children[1].type == EntityType.elementEmpty);
32     assert(foo.children[1].name == "whatever");
33 
34     assert(root.children[1].type == EntityType.elementEmpty);
35     assert(root.children[1].name == "bar");
36 
37     assert(root.children[2].type == EntityType.elementStart);
38     assert(root.children[2].name == "baz");
39     assert(root.children[2].children.length == 0);
40 }
41 {
42     auto dom = parseDOM!simpleXML(xml);
43     assert(dom.type == EntityType.elementStart);
44     assert(dom.name.empty);
45     assert(dom.children.length == 1);
46 
47     auto root = dom.children[0];
48     assert(root.type == EntityType.elementStart);
49     assert(root.name == "root");
50     assert(root.children.length == 3);
51 
52     auto foo = root.children[0];
53     assert(foo.type == EntityType.elementStart);
54     assert(foo.name == "foo");
55     assert(foo.children.length == 2);
56 
57     assert(foo.children[0].type == EntityType.text);
58     assert(foo.children[0].text == "some text");
59 
60     assert(foo.children[1].type == EntityType.elementStart);
61     assert(foo.children[1].name == "whatever");
62     assert(foo.children[1].children.length == 0);
63 
64     assert(root.children[1].type == EntityType.elementStart);
65     assert(root.children[1].name == "bar");
66     assert(root.children[1].children.length == 0);
67 
68     assert(root.children[2].type == EntityType.elementStart);
69     assert(root.children[2].name == "baz");
70     assert(root.children[2].children.length == 0);
71 }

See Also

Meta

Source

See Source File
$(LINK_TO_SRC dxml/_dom.d)