Hello,
I must implement a such parser (based on a LL(1) grammar). I did this
try {
// Create the reader.
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
XmlReader reader = XmlReader.Create(new XmlTextReader(filename), settings);
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
Hashtable attributes = new Hashtable();
string strURI = reader.NamespaceURI;
string strName = reader.Name;
Console.Write(strURI + " " + "<" + strName );
if (reader.HasAttributes) {
for (int i = 0; i < reader.AttributeCount; i++) {
reader.MoveToAttribute(i);
attributes.Add(reader.Name, reader.Value);
Console.Write(" " + reader.Name + "=" + "\"" + reader.Value + "\"");
}
Console.WriteLine(">");
}
else {
Console.WriteLine(">");
}
break;
case XmlNodeType.EndElement:
string strNameEND = reader.Name;
Console.WriteLine("" + strNameEND + ">");
break;
// Todo
//case XmlNodeType.Text:
// Todo
default:
break;
}
}
Can I say that using SAx I'm doing a recursive descent parser or not?
thanks
Loading
Roei BarPosted Sep 22, 2009, 2:54 PM
if you would load the xml and then say
if node.childNodes.Count > 1
recall your method with the current next node and redo the same,
meaning that the switch will be called by the current node only in the end and then return to the one before and so on
MarcoPosted Sep 22, 2009, 1:42 PM
thanks
Roei BarPosted Sep 22, 2009, 1:19 PM
like the following
you need to do this
call a function to handle the reader, and hold the switch case
and whenever its an Element recall the function with the ChildNode