Tuesday, February 24th, 2009 | Author: admin
The XML File
<client_order ordID="14" supplierID="000002"> <item_order itoItemID="12" itoItemQty="1" itoItemPrice="35.99" itoTaxAmount="3.00" itemCode="LD3162" /> <item_order itoItemID="3" itoItemQty="0" itoItemPrice="29.99" itoTaxAmount="3.00" itemCode="LD3278" /> <item_order itoItemID="7" itoItemQty="0" itoItemPrice="31.99" itoTaxAmount="3.00" itemCode="LD3226" /> <item_order itoItemID="10" itoItemQty="0" itoItemPrice="31.99" itoTaxAmount="3.00" itemCode="LD3226" /> <item_order itoItemID="9" itoItemQty="0" itoItemPrice="29.99" itoTaxAmount="3.00" itemCode="LD3226" /> </client_order>
The CODE ;o)
//Get the XML string responseXML = r["Response"].ToString(); try { XmlDocument contentXML = new XmlDocument(); contentXML.LoadXml(responseXML); //Get the attribute values from the root node <client_order> XmlNode client_orderNode = contentXML.DocumentElement.SelectSingleNode("//client_order"); string supplierID = client_orderNode.Attributes["supplierID"].Value.ToString(); string ordID = client_orderNode.Attributes["ordID"].Value.ToString(); string supplierName = CommonDBCommands.SelectValue(connectionString, "suppliers", "supplierName", "supplierID", supplierID); //GET the order id and supplier as recorded in the XML response. Debug.Print("Supplier ID = " + supplierID); Debug.Print("Order ID = " + ordID); //read each element <item_order> in <client_order> and get the attribute values foreach (XmlNode node in client_orderNode) { XmlElement item_order = (XmlElement)node; string itemID = ""; string itemQty = ""; string itemPrice = ""; string itemTaxAmount = ""; string itemCode = ""; if (item_order.HasAttributes) { itemID = item_order.Attributes["itoItemID"].InnerText; itemQty = item_order.Attributes["itoItemQty"].InnerText; itemPrice = item_order.Attributes["itoItemPrice"].InnerText; itemTaxAmount = item_order.Attributes["itoTaxAmount"].InnerText; itemCode = item_order.Attributes["itemCode"].InnerText; if (itemID == hItemID) { DataRow row = dt.NewRow(); row["SupplierName"] = supplierName; row["itemID"] = itemID; row["Qty"] = Convert.ToDecimal(itemQty); row["price"] = Convert.ToDecimal(itemPrice); row["taxAmount"] = Convert.ToDecimal(itemTaxAmount); row["itemCode"] = itemCode; dt.Rows.Add(row); } } Debug.Print("item ID = " + itemID); Debug.Print("price = $" + itemPrice); } } catch (Exception ex) { Response.Write(ex.Message.ToString()); }
