0

Hi I have xmlFile like below .My problem is that I cant iterate through all nodes.I have tried something like this .But I think its to diffucult for me .I am so cunfused.How can do this without Linq To Xml

protected void Page_Load(object sender, System.EventArgs e)
    {
        string xmlFile = Request.PhysicalApplicationPath + @"myxml.xml";
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.IgnoreComments = true;
        settings.IgnoreWhitespace = true;

        using (XmlReader reader = XmlReader.Create(Server.MapPath("myxml.xml"), settings)) {
            while (reader.Read()) {
                string xmlContent = "";
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "Book") {

                    while (reader.NodeType != XmlNodeType.EndElement)
                    {



                    }
                    Label1.Text = xmlContent;
                }

            }

        }

    }

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--This is sample book store xml file.-->
<books>
  <book>
    <id>1</id>
    <name>Photodex ProShow: Visual QuickStart Guide</name>
    <author>Jon Canfield</author>
    <price>$29.99</price>
    <type>Photoshop</type>
  </book>

</books>
2
Contributors
1
Reply
22
Views
3 Years
Discussion Span
Last Post by castajiz_2
0

I think that this is the simplest way to do this.

List<string> list=new List<string>();
XmlDocument doc = new XmlDocument();
                doc.Load("string path or url");
                XmlNodeReader nodereader = new XmlNodeReader(doc);
                while (nodereader.Read())
                {
                    if (nodereader.NodeType == XmlNodeType.Element)
                        list.Add(nodereader.LocalName);
                }
            }
            foreach (string node in list) 

            {
                MessageBox.Show(node);
            }

if you .xml file is located on your hard drive than use the OpenFileDialog class otherwise if it s on the web that put your url as a string.

Edited by castajiz_2: forgot something

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.