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 BarRank #1,271 · 1.4K reputationPosted Sep 22, 2009, 9:19 AM EDT
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
Marco59 reputationPosted Sep 22, 2009, 9:42 AM EDT
thanks
Roei BarRank #1,271 · 1.4K reputationPosted Sep 22, 2009, 10:54 AM EDT
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