XmlDocument- Using GetElementsByTagName with index in asp.net xml
GetElementsBytagNameIndex.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Xml" %>
<!DOCTYPE html>
<script runat="server">
void Button1_Click(object sender, System.EventArgs e)
{
BulletedList1.Items.Clear();
string xmlPath = Request.PhysicalApplicationPath + @"App_Data\ITBookList.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlPath);
XmlNode nameNode = xmlDoc.GetElementsByTagName(TextBox1.Text)[3];
BulletedList1.Items.Add(nameNode.FirstChild.Value);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>XmlDocument- Using GetElementsByTagName with index in asp.net xml</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">XmlDocument Example: GetElementsByTagName With Index</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
Text="Input Node Name"
ForeColor="DeepPink"
>
</asp:Label>
<asp:TextBox
ID="TextBox1"
runat="server"
Text="name"
ForeColor="Snow"
Width="250"
BackColor="DeepPink"
Height="35"
Font-Bold="true"
>
</asp:TextBox>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Find Nodes [GetElementsByTagName] With Index [3]"
Height="42"
Font-Bold="true"
ForeColor="SaddleBrown"
/>
<br /><br />
<asp:BulletedList
ID="BulletedList1"
runat="server"
ForeColor="HotPink"
Font-Size="Large"
BulletStyle="Square"
Font-Names="Comic Sans MS"
>
</asp:BulletedList>
</div>
</form>
</body>
</html>
ITBookList.xml
ITBookList.xml source code here.


- XSLT xsl:value-of - How to get, select xml element value using xslt
- XSLT xsl:param - How to use parameter in xslt
- XSLT xsl:choose, xsl:when, xsl:otherwise - How to use them in xslt
- XSLT - How to test, evaluate multiple conditions in xslt
- XSLT xsl:template - How to use xsl:template in xslt
- XmlDocument GetElementsByTagName - how to find nodes by name in asp.net xml
- XmlDocument SelectNodes() method - How to select nodes in asp.net xml
- XmlDocument SelectSingleNode() method - How to select single node in asp.net xml