Geeks With Blogs
Gaurav Taneja Great dreams... never even get out of the box. It takes an uncommon amount of guts to put your dreams on the line, to hold them up and say, "How good or how bad am I?" That's where courage comes in.

public void ExtractNodes()

{

string HoldTheOrder = "";

//HttpPostedFile myFile = DatFile.PostedFile;

//if ((myFile.FileName == null) || (myFile.FileName.Equals("")))

//{

// lblConfirm.Text = "Path is not correct!";

// return;

//}

string DestinationPath = @"C:\XMLOutput.txt";  //// create a file for output

SWrtr = new StreamWriter(DestinationPath);

XmlTextReader XMLRdr = new XmlTextReader("c:\\gt.xml"); // path of the xml file

bool Flag;

while (XMLRdr.Read())

{

Flag = false;

switch (XMLRdr.NodeType)

{

case XmlNodeType.Element:

Flag = true;

HoldTheOrder = HoldTheOrder + ((HoldTheOrder.Length > 0) ? " -> " : "") + XMLRdr.Name;

break;

case XmlNodeType.Text:

break;

case XmlNodeType.EndElement:

Flag = false;

if (HoldTheOrder.LastIndexOf(" -> " + XMLRdr.Name) > -1) HoldTheOrder = HoldTheOrder.Substring(0, HoldTheOrder.LastIndexOf(" -> " + XMLRdr.Name));

break;

}

if (Flag)

{

SWrtr.Write(HoldTheOrder);

Response.Write("<br>" + HoldTheOrder);

SWrtr.WriteLine("");

}

}

//lblConfirm.Text = "File Successfully Creadted at [" + DestinationPath + "]";

SWrtr.Dispose();

SWrtr = null;

XMLRdr.Close();

XMLRdr = null;

}

Posted on Thursday, February 15, 2007 10:56 AM | Back to top


Comments on this post: Traverse XML

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Gaurav Taneja | Powered by: GeeksWithBlogs.net