Databases Reference
In-Depth Information
}
...
//Assistant's name
XmlNodeList assistantname =
selXmlDoc.SelectNodes("/cust:customerinfo/cust:assistant/cust:name",
nsmgr);
foreach (XmlElement anameinfo in assistantname)
{
String assistname = anameinfo.InnerXml;
}
The value of the element is extracted using:
XmlElement.InnerXml(localname, XmlNamespaceManager).
The value of the attribute is extracted using:
XmlElement.GetAttribute(localname, XmlNamespaceManager).
The XmlNodeList implements IEnumerable interface, and thus it can be
accessed using IEnumberator methods. The code, which selects INFO XML
column from the customer table is implemented in SelectCustomer() method as
shown in Example 6-10.
Example 6-10 Selecting customer information
public static void SelectCustomer(DB2Connection conn, int pcid)
{
//Select the data according to cid.
DB2Command cmd = conn.CreateCommand();
XmlDocument selXmlDoc = new XmlDocument();
String selectStmt="SELECT info from customer WHERE cid = " + pcid +
";" ;
Console.WriteLine("\nSelect Stmt: \n"+selectStmt);
cmd.CommandText= selectStmt;
XmlReader xr = cmd.ExecuteXmlReader();
try{
//if following XmlNamespaceMangaer is not added no node will be
selected as given XML data contains xmlns
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xr.NameTable);
nsmgr.AddNamespace("cust", "http://posample.org");
Console.WriteLine("\nSelecting using xmlreader\n");
selXmlDoc.Load(xr);
Search WWH ::




Custom Search