例:获取的xml如下:
<rs:data>
<z:row id="1000000053" pbvid="1000000015" cinvcode="EFYS0004" cinvname="螺钉" cinvstd="M2x6 _GB/T 70.1-2008 内六角圆柱头螺钉,强度等级12.9级"
cinvccode="8001" cinvm_unit="pcs" igrouptype="0" cgroupcode="101" cbaccounter="" bservice="False" iinvexchrate=".00000000" binvbatch="True"
ipbvquantity="2000.0000000000" inum=".0000000000" ioricost=".2035000000" iorimoney="407.08" ioritaxprice="52.92" iorisum="460"
icost=".2035000000" imoney="407.08" itaxprice="52.92" isum="460" ioritotal="0" itotal="0" bexbill="False" binvtype="False"
itaxrate="13.0000000000" ccomunitcode="101" ioritaxcost=".230000" isPayment="0" isSettle="0" bcosting="False" btaxcost="True"
brettax="0" ivouchrowno="1" cinvcname="辅料-装配辅料" cbsysbarcode="||puzl|20210105|1" bgift="0" cbatch="0000" editprop="" />
<z:row id="1000000054" pbvid="1000000015" cinvcode="EFYS0006" cinvname="螺钉" cinvstd="国标M3x6 杯头内六角,12.9级镀黑镍,材质合金钢。"
cinvccode="8001" cinvm_unit="pcs" igrouptype="0" cgroupcode="101" cbaccounter="" bservice="False" iinvexchrate=".00000000" binvbatch="True"
ipbvquantity="3000.0000000000" inum=".0000000000" ioricost=".1593000000" iorimoney="477.88" ioritaxprice="62.12" iorisum="540"
icost=".1593000000" imoney="477.88" itaxprice="62.12" isum="540" ioritotal="0" itotal="0" bexbill="False" binvtype="False"
itaxrate="13.0000000000" ccomunitcode="101" ioritaxcost=".180000" isPayment="0" isSettle="0" bcosting="False" btaxcost="True" brettax="0"
ivouchrowno="2" cinvcname="辅料-装配辅料" cbsysbarcode="||puzl|20210105|2" bgift="0" cbatch="0000" editprop="" />
</rs:data>
注释:这是取子表内容,取节点z:row数据.
后台实现方法
public bool XML(ref IXMLDOMDocument2 domhead, ref IXMLDOMDocument2 dombody, ref string errmsg)
{
XmlDocument dbd = new XmlDocument();
Dictionary<string, string> headdic = new Dictionary<string, string>();
dbd.LoadXml(dombody.xml);
XmlNamespaceManager nsp = new XmlNamespaceManager(dbd.NameTable);
nsp.AddNamespace("z", "#RowsetSchema");
XmlElement xmlElem = dbd.DocumentElement;
XmlNodeList topM = dbd.LastChild.LastChild.SelectNodes("z:row", nsp);
List<object> jsonlist = new List<object>();
foreach (XmlElement element in topM)
{
Dictionary<string, string> zibiao = new Dictionary<string, string>();
XmlElement el = (XmlElement)element;
string chmc = el.GetAttribute("cinvcname");
string chbm = el.GetAttribute("cinvcode");
zibiao.Add("chmc", chmc);
zibiao.Add("chbm", chbm);
jsonlist.Add(zibiao);
}
}