C# xml取指定节点值 存List

:获取的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 dct = new XmlDocument();
            //-----------------------加载头-----------------------
            //dct.LoadXml(domhead.xml);

            //-----------------------加载体-----------------------
            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");
            
            //string docc = dbd.LastChild.LastChild.LastChild.OuterXml;
            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);
            }
      }
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值