Databases Reference
In-Depth Information
If you want to differentiate elements of same name in different nodes, you can
specify the specific XPath.
For example, in the CUSTOMER table, we have two instances of < name > in the
XML document for the “info” column. One is for name of the customer and the
other is for the assistant's name as shown in Figure 6-13.
Figure 6-13 Sample info XML data from the CUSTOMER table
The XPath shown in Example 6-8 can be specified in the SelectNodes() to obtain
all the names in the given XML document (customer's and assistant's).
Example 6-8 Selecting all names
XmlNodeList customername= selXmlDoc.SelectNodes("//cust:name", nsmgr);
foreach (XmlElement nameinfo in customername)
{
String vname=nameinfo.InnerXml;
}
The XPath in Example 6-9 can be specified in the SelectNodes() to obtain
customer's name and assistant's name respectively.
Example 6-9 Obtain customer's name and assistant's name respectively
//Customer's name
XmlNodeList customername =
selXmlDoc.SelectNodes("/cust:customerinfo/cust:name", nsmgr);
foreach(XmlElement nameinfo in customername)
{
String custname = nameinfo.InnerXml;
Search WWH ::




Custom Search