Read From Xml File...Approach 1
private static void ReadXMLApproach2()
{
pathForFile = @"D:\Study\books.xml";
FileStream filestreamSource = new FileStream(pathForFile, FileMode.Open, FileAccess.Read);
XmlTextReader reader = new XmlTextReader( filestreamSource );
LoopThroughXMLTextReader(reader);
reader.Close();
}
private static void LoopThroughXMLTextReader(XmlTextReader reader)
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.XmlDeclaration:
Console.WriteLine (reader.Name + " ....xmlDeclaration" + reader.Value);
break;
case XmlNodeType.ProcessingInstruction:
Console.WriteLine(reader.Name + " ....ProcessingInstruction" + reader.Value);
break;
case XmlNodeType.DocumentType:
Console.WriteLine(reader.Name + " ....DocumentType" + reader.Value);
break;
case XmlNodeType.Comment:
Console.WriteLine(reader.Name + " ....Comment" + reader.Value);
break;
case XmlNodeType.Element:
Console.WriteLine(reader.Name + " ....Element" + reader.Value);
break;
case XmlNodeType.Text:
Console.WriteLine(reader.Name + " ....Text" + reader.Value);
break;
case XmlNodeType.Whitespace:
break;
}
}
}
{
pathForFile = @"D:\Study\books.xml";
FileStream filestreamSource = new FileStream(pathForFile, FileMode.Open, FileAccess.Read);
XmlTextReader reader = new XmlTextReader( filestreamSource );
LoopThroughXMLTextReader(reader);
reader.Close();
}
private static void LoopThroughXMLTextReader(XmlTextReader reader)
{
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.XmlDeclaration:
Console.WriteLine (reader.Name + " ....xmlDeclaration" + reader.Value);
break;
case XmlNodeType.ProcessingInstruction:
Console.WriteLine(reader.Name + " ....ProcessingInstruction" + reader.Value);
break;
case XmlNodeType.DocumentType:
Console.WriteLine(reader.Name + " ....DocumentType" + reader.Value);
break;
case XmlNodeType.Comment:
Console.WriteLine(reader.Name + " ....Comment" + reader.Value);
break;
case XmlNodeType.Element:
Console.WriteLine(reader.Name + " ....Element" + reader.Value);
break;
case XmlNodeType.Text:
Console.WriteLine(reader.Name + " ....Text" + reader.Value);
break;
case XmlNodeType.Whitespace:
break;
}
}
}
0 Comments:
Post a Comment
<< Home