How to Select XML Type Nodes in ASP
XML node types let you specify properties for your data to distinguish the data from other lists of definitions. You use the "SelectNodes" function to retrieve nodes that have a specific node type attribute.
Instructions
-
-
1
Click the Windows "Start" button and select "All Programs." Click "Microsoft .NET Framework," then choose "Visual Studio" to open the ASP programming software. Open your ASP project in the software.
-
2
Double-click the code file you want to use to search the XML data. The code file opens in your editor.
-
-
3
Load the XML data, if you do not already have an XML variable created. The following code loads an XML string in ASP.NET:
XmlDocument doc = new XmlDocument();
doc.LoadXml(str); -
4
Point the compiler to a node with a specific property. For instance, the following code points to a node with a type labeled "Female":
XmlNodeList nodes = xml.SelectNodes("/Customers/customer[@type='Female'");
The code above gets a list of female customers.
-
5
Display the data to the user. The following code displays the first customer:
Console.WriteLine(nodes[0].InnerText);
-
1