Created
July 8, 2009 06:07
-
-
Save jarodl/142619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ParseFile(string strPath) | |
{ | |
XmlTextReader xmlReader = new XmlTextReader(strPath); | |
int iTab = 0; | |
// Read the line of the xml file | |
while (xmlReader.Read()) | |
{ | |
switch (xmlReader.NodeType) | |
{ | |
case XmlNodeType.Element: | |
Hashtable attributes = new Hashtable(); | |
// We add the attributes to the hash tables | |
bool isEmptyElement = false; | |
PrintWhiteSpace(iTab); | |
// Print the start of the element | |
Console.Write("<" + xmlReader.Name); | |
isEmptyElement = xmlReader.IsEmptyElement; | |
if (xmlReader.HasAttributes) | |
{ | |
// If element has attributes | |
for (int i = 0; i < xmlReader.AttributeCount; i++) | |
{ | |
xmlReader.MoveToAttribute(i); | |
attributes.Add(xmlReader.Name, xmlReader.Value); | |
Console.Write(" " + xmlReader.Name + "=" + xmlReader.Value); | |
} | |
} | |
// Prints the end of the element | |
if (isEmptyElement == true) | |
{ | |
Console.WriteLine(" />"); | |
} | |
else | |
{ | |
Console.WriteLine(">"); | |
iTab++; | |
} | |
break; | |
case XmlNodeType.EndElement: | |
iTab--; | |
PrintWhiteSpace(iTab); | |
Console.WriteLine("</" + xmlReader.Name + ">"); | |
break; | |
case XmlNodeType.Text: | |
PrintWhiteSpace(iTab); | |
Console.WriteLine(xmlReader.Value); | |
break; | |
default: | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment