XMLReader parsing peculiarities

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
using (XMLReader reader)
Im attempting to parse an Apple plist as XML (i.e. stripped of the 3 plist specific lines).
I can step through the entire doc with reader.Read() and see all the nodes etc. but
when I parse it, I use code like this:


do
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "key":
reader.Read();
key = reader.Value;
break;
case "string":
reader.Read();
value = reader.Value;
partsInfoDict.Add(key, value);
key = value = ""; break; // debug
case "array":
subTree = reader.ReadSubtree();
// call some method to process subTree
tempBookmarkArrayList = readBookmarkSubTree(subTree);
partsInfoDict.Add(key, tempBookmarkArrayList);
subTree.Close(); // bail out of this, go back up to main XMLReader
reader.ReadToNextSibling("dict");
reader.ReadToNextSibling("dict");
key = value = ""; break; // debug
}
}
} while (keepDoingThisLoop == true && reader.Read());


I get a couple of exceptions at various points in parsing, e.g. when processing the 2nd subtree, this statement: partsInfoDict.Add(key, value); yields "Value does not fall within expected range" for the "value" which is a string. At this point
Ive already added dozens of <string,string> entries to either this dictionary or other dictionaries. This dictionary is actually <string, Object> whereas the others are <string, string> types.
Any ideas why this blows up after successfully processing several nodes?

The other exception is "not supported exception" and happens when I use slightly more exotic methods like reader.ReadTo[Following, NextSibling, etc]. Sometimes these methods succeed and other times they dont, when testing inside different VS2010 projects.
Either it works in the project or doesnt. Unlike the first case (above) there has never been a "works for a while, then doesnt" situation.
Any ideas why? And, any ideas how I can get more useful information than "not supported exception"?

View the full article
 
Back
Top