annotate orange/xml/XMLDocument.d @ 26:78e5fef4bbf2 experimental

Third step in refactoring the API. Stating to add unit tests.
author Jacob Carlborg <doob@me.com>
date Tue, 19 Oct 2010 10:22:10 +0200
parents 9a575087b961
children 511d1ef4e299
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1 /**
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
2 * Copyright: Copyright (c) 2010 Jacob Carlborg.
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
3 * Authors: Jacob Carlborg
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
4 * Version: Initial created: Jun 26, 2010
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
6 */
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
7 module orange.xml.XMLDocument;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
8
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
9 version (Tango)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
10 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
11 import tango.text.xml.DocPrinter;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
12 import tango.text.xml.Document;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
13 import tango.io.Stdout;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
14
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
15 import orange.core.string;
9
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
16 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
17
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
18 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
19 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
20 import std.string;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
21 import std.stdio;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
22
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
23 import orange.xml.PhobosXML;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
24
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
25 version = Phobos;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
26 }
20
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
27
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
28 import orange.core.io;
9
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
29
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
30 template Char (T)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
31 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
32 version (Tango)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
33 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
34 static if (is(T == char) || is(T == wchar) || is(T == dchar))
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
35 alias T Char;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
36
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
37 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
38 static assert(false, `The given type "` ~ T.stringof ~ `" is not a vaild character type, valid types are "char", "wchar" and "dchar".`);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
39 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
40
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
41 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
42 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
43 static if (is(T == char))
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
44 alias T Char;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
45
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
46 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
47 static assert(false, `The given type "` ~ T.stringof ~ `" is not a vaild character type, the only valid type is "char".`);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
48 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
49 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
50
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
51 class XMLException : Exception
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
52 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
53 version (Tango) private alias long Line;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
54 else private alias size_t Line;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
55
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
56 this (string message, string file = null, Line line = 0)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
57 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
58 super(message, file, line);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
59 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
60 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
61
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
62 final class XMLDocument (T = char)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
63 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
64 version (Tango)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
65 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
66 alias Document!(T) Doc;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
67 alias Doc.Node InternalNode;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
68 alias XmlPath!(T).NodeSet QueryNode;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
69 alias T[] tstring;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
70 alias Doc.Visitor VisitorType;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
71 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
72
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
73 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
74 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
75 alias Document Doc;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
76 alias Element InternalNode;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
77 alias Element QueryNode;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
78 alias string tstring;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
79 alias Element[] VisitorType;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
80 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
81
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
82 struct VisitorProxy
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
83 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
84 private VisitorType nodes;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
85
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
86 private static VisitorProxy opCall (VisitorType nodes)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
87 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
88 VisitorProxy vp;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
89 vp.nodes = nodes;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
90
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
91 return vp;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
92 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
93
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
94 bool exist ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
95 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
96 version (Tango) return nodes.exist;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
97 else return nodes.length > 0;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
98 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
99
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
100 int opApply (int delegate (ref Node) dg)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
101 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
102 int result;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
103
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
104 foreach (n ; nodes)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
105 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
106 auto p = Node(n);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
107 result = dg(p);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
108
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
109 if (result)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
110 break;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
111 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
112
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
113 return result;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
114 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
115 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
116
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
117 struct Node
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
118 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
119 private InternalNode node;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
120
20
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
121 version (Tango)
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
122 {
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
123 private static Node opCall (InternalNode node)
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
124 {
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
125 Node proxy;
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
126 proxy.node = node;
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
127
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
128 return proxy;
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
129 }
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
130 }
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
131
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
132 else
9
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
133 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
134 private bool shouldAddToDoc = true;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
135 private bool isRoot = true;
20
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
136
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
137 private static Node opCall (InternalNode node, bool shouldAddToDoc = false, bool isRoot = false)
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
138 {
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
139 Node proxy;
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
140 proxy.node = node;
9
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
141 proxy.shouldAddToDoc = shouldAddToDoc;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
142 proxy.isRoot = isRoot;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
143
20
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
144 return proxy;
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
145 }
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
146 }
9
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
147
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
148 public static Node invalid ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
149 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
150 return Node(null);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
151 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
152
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
153 tstring name ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
154 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
155 return node.name;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
156 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
157
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
158 tstring value ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
159 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
160 return node.value;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
161 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
162
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
163 Node parent ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
164 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
165 return Node(node.parent);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
166 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
167
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
168 bool isValid ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
169 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
170 return node !is null;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
171 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
172
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
173 VisitorProxy children ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
174 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
175 return VisitorProxy(node.children);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
176 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
177
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
178 VisitorProxy attributes ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
179 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
180 return VisitorProxy(node.attributes);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
181 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
182
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
183 QueryProxy query ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
184 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
185 return QueryProxy(node.query);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
186 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
187
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
188 Node element (tstring name, tstring value = null)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
189 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
190 version (Tango) return Node(node.element(null, name, value));
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
191
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
192 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
193 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
194 auto element = new Element(name, value);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
195
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
196 if (isRoot)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
197 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
198 node.tag = element.tag;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
199 node ~= new Text(value);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
200
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
201 return Node(node, true, false);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
202 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
203
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
204 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
205 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
206 if (shouldAddToDoc)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
207 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
208 shouldAddToDoc = false;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
209 node ~= element;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
210 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
211
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
212 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
213 node ~= element;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
214
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
215 return Node(element, shouldAddToDoc, false);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
216 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
217 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
218 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
219
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
220 Node attribute (tstring name, tstring value)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
221 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
222 node.attribute(null, name, value);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
223
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
224 version (Tango) return *this;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
225 else return this;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
226 }
20
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
227
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
228 void attach (Node node)
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
229 {
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
230 version (Tango) this.node.move(node.node);
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
231 else this.node.elements ~= node.node;
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
232 }
9
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
233 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
234
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
235 struct QueryProxy
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
236 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
237 version (Tango)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
238 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
239 private QueryNode node;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
240 private bool delegate (Node) currentFilter;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
241 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
242
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
243 version (Phobos) private Node[] nodes_;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
244
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
245 private static QueryProxy opCall (QueryNode node)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
246 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
247 QueryProxy qp;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
248
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
249 version (Tango) qp.node = node;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
250 else qp.nodes_ = [Node(node)];
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
251
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
252 return qp;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
253 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
254
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
255 version (Phobos)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
256 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
257 private static QueryProxy opCall (Node[] nodes)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
258 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
259 QueryProxy qp;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
260 qp.nodes_ = nodes;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
261
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
262 return qp;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
263 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
264 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
265
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
266 version (Tango)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
267 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
268 private bool internalFilter (InternalNode node)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
269 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
270 return currentFilter(Node(node));
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
271 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
272 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
273
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
274 QueryProxy attribute (bool delegate (Node) filter)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
275 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
276 version (Tango)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
277 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
278 this.currentFilter = filter;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
279 return QueryProxy(node.attribute(&internalFilter));
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
280 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
281
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
282 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
283 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
284 Node[] nodes;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
285
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
286 foreach (node ; nodes_)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
287 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
288 foreach (attr ; node.attributes.nodes)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
289 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
290 auto n = Node(attr);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
291
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
292 if (filter && filter(n))
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
293 nodes ~= n;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
294 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
295 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
296
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
297 return QueryProxy(nodes);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
298 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
299 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
300
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
301 QueryProxy attribute (tstring name = null)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
302 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
303 version (Tango) return QueryProxy(node.attribute(name));
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
304
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
305 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
306 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
307 bool filter (Node node)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
308 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
309 return node.name == name;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
310 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
311
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
312 bool always (Node node)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
313 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
314 return true;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
315 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
316
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
317 if (name.length > 0)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
318 return attribute(&filter);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
319
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
320 return attribute(&always);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
321 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
322 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
323
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
324 Node[] nodes ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
325 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
326 version (Tango)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
327 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
328 auto proxies = new Node[node.nodes.length];
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
329
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
330 foreach (i, node ; node.nodes)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
331 proxies[i] = Node(node);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
332
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
333 return proxies;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
334 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
335
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
336 else return nodes_;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
337 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
338
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
339 QueryProxy opIndex (tstring query)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
340 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
341 version (Tango) return QueryProxy(node[query]);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
342
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
343 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
344 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
345 Node[] proxies;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
346
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
347 foreach (parent ; nodes_)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
348 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
349 if (parent.name == query)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
350 proxies ~= parent;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
351
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
352 foreach (e ; parent.node.elements)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
353 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
354 if (e.tag.name == query)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
355 proxies ~= Node(e);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
356 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
357 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
358
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
359 return QueryProxy(proxies);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
360 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
361 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
362
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
363 int opApply (int delegate (ref Node) dg)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
364 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
365 version (Tango) auto visitor = node;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
366 else auto visitor = nodes_;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
367
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
368 int result;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
369
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
370 foreach (n ; visitor)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
371 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
372 version (Tango)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
373 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
374 auto p = Node(n);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
375 result = dg(p);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
376 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
377
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
378 else result = dg(n);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
379
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
380 if (result)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
381 break;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
382 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
383
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
384 return result;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
385 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
386 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
387
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
388 ///
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
389 bool strictErrorChecking;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
390
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
391 ///
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
392 uint indentation = 4;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
393
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
394 private Doc doc;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
395 version (Tango) private DocPrinter!(T) printer;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
396 else InternalNode currentNode;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
397
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
398 this (bool strictErrorChecking = true)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
399 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
400 version (Tango) doc = new Doc;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
401 else doc = new Doc(new Tag("root"));
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
402 this.strictErrorChecking = strictErrorChecking;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
403 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
404
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
405 XMLDocument header (tstring encoding = null)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
406 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
407 version (Tango) doc.header(encoding);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
408
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
409 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
410 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
411 tstring newEncoding = encoding.length > 0 ? encoding : "UTF-8";
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
412 tstring header = `<?xml version="1.0" encoding="` ~ newEncoding ~ `"?>`;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
413 doc.prolog = header;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
414 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
415
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
416 return this;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
417 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
418
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
419 XMLDocument reset ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
420 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
421 version (Tango) doc.reset;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
422 else doc = new Doc(new Tag("root"));
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
423
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
424 return this;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
425 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
426
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
427 Node tree ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
428 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
429 version (Tango) return Node(doc.tree);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
430 else return Node(doc, true, true);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
431 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
432
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
433 void parse (tstring xml)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
434 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
435 version (Tango) doc.parse(xml);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
436 else doc = new Doc(xml);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
437 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
438
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
439 QueryProxy query ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
440 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
441 version (Tango) return QueryProxy(doc.tree.query);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
442 else return QueryProxy(doc);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
443 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
444
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
445 string toString ()
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
446 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
447 version (Tango)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
448 {
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
449 if (!printer)
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
450 printer = new DocPrinter!(T);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
451
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
452 printer.indent = indentation;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
453 return printer.print(doc);
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
454 }
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
455
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
456 else
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
457 return doc.prolog ~ "\n" ~ join(doc.pretty(indentation), "\n");
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
458 }
20
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
459
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
460 Node createNode (tstring name, tstring value = null)
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
461 {
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
462 version (Tango) return Node(tree.element(name, value).node.detach);
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
463 else return Node(new Element(name, value), false, false);
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 10
diff changeset
464 }
9
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
diff changeset
465 }