如何取XML中某节点的值

来源:百度知道 编辑:UC知道 时间:2024/07/03 04:19:33
<?xml version="1.0" encoding="gb2312" ?>
- <SupplyWeb_Data>
- <Receipt>
- <Receipt_Header>
<transaction_type value="adjustment" />
<receipt_id value="5000028289000012009" />
<facility_id value="1100" />
<supplier_id value="400052" />
<ship_to_id value="1100" />
<shipper_no value="100000011" />
<ship_date_time value="2009-10-10 02:04:37" />
<receipt_date_time value="2009-10-13 13:28:32" />
</Receipt_Header>
- <Receipt_Detail>
<cust_part_no value="000000009759904480" />
<po_number value="5500000389" />
<po_line_no value="00040" />
<ship_quantity value="10000.000" />
<received_quantity value="10000.000"

(C#)
XmlDataDocument xd = new XmlDataDocument();
xd.Load(System.Web.HttpContext.Current.Server.MapPath("Xmlfile.xml"));
XmlNode xn = xd.SelectSingleNode(@"/SupplyWeb_Data/Receipt/Receipt_Detail/ship_quantity[@value]");
Response.Write(xn.Attributes["value"].Value);

先定位到ship_quantity,然后定位到"记住位置,在定位到下一个",两个位置之间的取出来就行了

.net可以这样
要导入using System.Xml;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("xml的路径");
如果只有一个ship_quantity这样的节点
XmlNode root = xmlDoc.SelectSingleNode("ship_quantity").Attributes["value"].Value;