我还是一个xml白痴。有时我会得到它,有时候不会。 我有以下XML,它最终来自解析的.NET Web服务输出。为了这个问题,我把它包装在cfxml标签中,但实际上我正在解析一个xml文档。
<cfxml variable="local.vXML">
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<ResponseCode>3</ResponseCode>
<ResponseText>Incorrect PIN. Please try again</ResponseText>
</Table>
</NewDataSet>
</diffgr:diffgram>
</cfxml>
我想访问<ResponseCode>
和<ResponseText>
个节点。
我该怎么做?
各种努力,例如以下
<cfset Local.xSet = xmlSearch(local.vXML,"NewDataSet") />
<cfset Local.xSet = xmlSearch(local.vXML,"Table") />
<cfset Local.xSet = xmlSearch(local.vXML,"ResponseCode") />
产生一个空数组
感谢Jake的CF9解决方案。以下改编为CF8。
<cfset vResponseCodeXML = XMLSearch(Local.vXML, '//Table[@diffgr:id="Table1"]/ResponseCode')>
<cfset vResponseTextXML = XMLSearch(Local.vXML, '//Table[@diffgr:id="Table1"]/ResponseText')>
<cfset vResponseCode = vResponseCodeXML[1].XmlText>
<cfset vResponseText = vResponseTextXML[1].XmlText>
答案 0 :(得分:1)
试试这个:
<cfset respCode = XMLSearch(vXML, '//Table[@diffgr:id="Table1"]/ResponseCode')[1].XmlText>
<cfset respText = XMLSearch(vXML, '//Table[@diffgr:id="Table1"]/ResponseText')[1].XmlText>