<TALLYMESSAGE xmlns:UDF="TallyUDF">
<VOUCHER>
<ALLLEDGERENTRIES.LIST>
<LEDGERNAME>Cellular Mobile Pte Ltd</LEDGERNAME>
<AMOUNT>-2800000.00</AMOUNT>
</ALLLEDGERENTRIES.LIST>
<ALLLEDGERENTRIES.LIST>
<LEDGERNAME>ABC Bank</LEDGERNAME>
</ALLLEDGERENTRIES.LIST>
</VOUCHER>
</TALLYMESSAGE>
当我写这段代码时
XmlNodeList dataNodes = xmlDoc.SelectNodes("VOUCHER");
foreach (XmlNode voucharbrandnode in dataNodes)
{ {
var amount=voucharbrandnode.SelectSingleNode("AMOUNT").InnerText
}
这显示异常,因为第二个节点中没有amount属性。 任何帮助表示赞赏
答案 0 :(得分:1)
检查节点存在。
XmlNode xmlNode = voucharbrandnode.SelectSingleNode("AMOUNT");
var amount = "";
if (xmlNode != null)
amount = xmlNode.InnerText;
答案 1 :(得分:0)
检查节点是否存在:
if(voucharbrandnode.SelectSingleNode("//AMOUNT")!=null)