{
// FIXME:
// - support XmlDictionaryReaderQuotas.
- // - support XmlBinaryReaderSession.
- // - handle namespaces as expected.
internal class XmlBinaryDictionaryReader : XmlDictionaryReader, IXmlNamespaceResolver
{
// 0 or more to fill later
public int NSSlot;
- string name;
- string local_name;
- string ns;
+ string name = String.Empty;
+ string local_name = String.Empty;
+ string ns = String.Empty;
string value;
public string LocalName {
{
base.Reset ();
ValueIndex = -1;
+ NodeType = XmlNodeType.Attribute;
}
}
}
public override int Depth {
- get { return depth; }
+ get { return current == node ? depth : NodeType == XmlNodeType.Attribute ? depth + 1 : depth + 2; }
}
public override bool EOF {
}
public override string Prefix {
- get { return current.Prefix; }
+ get { return current_attr >= 0 ? attributes [current_attr].Prefix : current.Prefix; }
}
+ // looks like it may return attribute's name even if it is on its value node.
public override string LocalName {
- get { return current.LocalName; }
+ get { return current_attr >= 0 ? attributes [current_attr].LocalName : current.LocalName; }
}
public override string NamespaceURI {
- get { return current.NS; }
+ get { return current_attr >= 0 ? attributes [current_attr].NS : current.NS; }
}
public override XmlNameTable NameTable {
current = attr_values [start];
return true;
}
+ // Actually there is no case for attribute whose value is split to more than two nodes. We could simplify the node structure.
+ /*
for (int i = start; i < end; i++) {
if (current == attr_values [i] && i + 1 < end) {
current = attr_values [i + 1];
return true;
}
}
+ */
return false;
}
}
else
node = node_stack [depth];
- node.Reset ();
current = node;
}
ProcessEndElement ();
return true;
}
- node.Reset ();
// process array node after preparing node stack.
switch (array_state) {
}
}
+ // array consumer does not expect Reset whlie it's on reading. So call it later than array check.
+ node.Reset ();
+
int ident = next >= 0 ? next : source.ReadByte ();
next = -1;
while (!reader.EOF)
reader.Read ();
+ // FIXME: use this instead; right now some tests are broken.
+ //XmlDocument doc = new XmlDocument ();
+ //doc.AppendChild (doc.CreateElement ("root"));
+ //while (!reader.EOF)
+ // doc.DocumentElement.AppendChild (doc.ReadNode (reader));
+ }
+
+ void AssertNode (XmlNodeType nodeType, string localName, string ns, string value, int depth, XmlReader reader, string label)
+ {
+ Assert.AreEqual (nodeType, reader.NodeType, label + ".Node");
+ Assert.AreEqual (localName, reader.LocalName, label + ".LocalName");
+ Assert.AreEqual (ns, reader.NamespaceURI, label + ".NS");
+ Assert.AreEqual (value, reader.Value, label + ".Value");
+ Assert.AreEqual (depth, reader.Depth, label + ".Depth");
}
[Test]
};
Read (bytes);
+
+ XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (bytes), new XmlDictionaryReaderQuotas ());
+ Assert.IsTrue (reader.Read (), "#1-1");
+ AssertNode (XmlNodeType.Element, "root", "urn:bar", "", 0, reader, "#1");
+ reader.MoveToAttribute (0);
+ if (reader.LocalName != "a")
+ reader.MoveToAttribute (1);
+ AssertNode (XmlNodeType.Attribute, "a", "", "", 1, reader, "#2");
+ Assert.IsTrue (reader.ReadAttributeValue (), "#3");
+ AssertNode (XmlNodeType.Text, "a", "", "", 2, reader, "#4");
+ Assert.IsFalse (reader.ReadAttributeValue (), "#5");
}
[Test]
[Test]
public void ReadInt16Array ()
{
- Read (array_int16);
+ Read (array_int32);
+
+ XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (array_int16), new XmlDictionaryReaderQuotas ());
+ Assert.IsTrue (reader.Read (), "#1-1");
+ AssertNode (XmlNodeType.Element, "el", "", "", 0, reader, "#1-2");
+ Assert.IsTrue (reader.Read (), "#2-1");
+ AssertNode (XmlNodeType.Text, "", "", "4", 1, reader, "#2-2");
+ Assert.IsTrue (reader.Read (), "#3-1");
+ AssertNode (XmlNodeType.EndElement, "el", "", "", 0, reader, "#3-2");
+ Assert.IsTrue (reader.Read (), "#4-1");
+ AssertNode (XmlNodeType.Element, "el", "", "", 0, reader, "#4-2");
+ Assert.IsTrue (reader.Read (), "#5-1");
+ AssertNode (XmlNodeType.Text, "", "", "6", 1, reader, "#5-2");
+ Assert.IsTrue (reader.Read (), "#6-1");
+ AssertNode (XmlNodeType.EndElement, "el", "", "", 0, reader, "#6-2");
+ for (int i = 0; i < 3; i++) // 6, 8, 10
+ for (int j = 0; j < 3; j++) // el / text / endel
+ Assert.IsTrue (reader.Read (), "#x-" + i + j);
+ Assert.IsFalse (reader.Read (), "End");
}
static readonly byte [] array_int16 = {