ASP.NET - Reading node values / elements from XML File

himavejella's picture

Reading values from XML File

using System.Xml; // for XmlTextreader
protected void Page_Load(object sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader(Server.MapPath("SyntaxHelp.xml"));
    //XmlText Reader reads the file node by node
           while (reader.Read())
            {
               switch (reader.NodeType)
               {
case XmlNodeType.Element: // The node is an element.
                    //do something
Response.Write(reader.Name+" -Element " );
Response.Write("
"); break; case XmlNodeType.Text: //Display the text in each element. //Do something Response.Write( reader.Value + " -Node
"); break; case XmlNodeType.EndElement: //Display the end of the element. //Do something Response.Write(reader.Name +" -End element"); Response.Write("
"); break; } } }

Here is XML File SyntaxHelp.xml

//SyntaxHelp.xml that is being referred in the page load
<?xml version="1.0" encoding="utf-8" ?>
<SyntaxHelp>
  <Cource>
    <ASP.NET>
      Working with Grid
    </ASP.NET>
    <VB.NET>
      Working with Files
    </VB.NET>
    <CSharp.NET>
      Working with LIST
    </CSharp.NET> 
  </Cource>

  <Cource>
    <ASP.NET>
      Working with Contols
    </ASP.NET>
    <VB.NET>
      Working with Dates
    </VB.NET>
    <CSharp.NET>
      Working with Data
    </CSharp.NET>
  </Cource>

  <Cource>
    <ASP.NET>
      Working with WebForms
    </ASP.NET>
    <VB.NET>
      Working with WinForms
    </VB.NET>
    <CSharp.NET>
      Working with ADO.NET
    </CSharp.NET>
  </Cource>
</SyntaxHelp>
Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.