如何选择节点“nfeStatusServicoNF2Result”?我尝试使用下面的代码,但 selectNodes 的结果为零。
代码示例
lXMLDoc := CoDOMDocument50.Create;
try
lXMLDoc.loadXML(lRespose.DataString);
lXMLDoc.setProperty('SelectionNamespaces', 'xmlns:n="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2"');
lXmlNodes := lXMLDoc.selectNodes('n:nfeStatusServicoNF2Result');
if lXmlNodes.length = 0 then
begin
lHostError := '';
lXmlNodes := lXMLDoc.getElementsByTagName('n:Value');
if lXmlNodes.length > 0 then
lHostError := lHostError + lXmlNodes.item[0].text;
lXmlNodes := lXMLDoc.getElementsByTagName('n:Text');
if lXmlNodes.length > 0 then
lHostError := lHostError + lXmlNodes.item[0].text;
if lHostError = '' then
lHostError := lRespose.DataString;
raise Exception.Create(lHostError);
end else
begin
Result := RemoveVersaoXML(lXmlNodes.item[0].text);
end;
finally
lXMLDoc := nil;
end;
xml文件
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
<cUF>31</cUF>
<versaoDados>2.00</versaoDados>
</nfeCabecMsg>
</soap:Header>
<soap:Body>
<nfeStatusServicoNF2Result xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
<retConsStatServ xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00">
<tpAmb>2</tpAmb>
<verAplic>13_0_96</verAplic>
<cStat>517</cStat>
<xMotivo>Rejeicao: Falha no schema XML - inexiste atributo versao na tag raiz da mensagem</xMotivo>
<cUF>31</cUF>
<dhRecbto>2013-08-08T17:45:48</dhRecbto>
</retConsStatServ>
</nfeStatusServicoNF2Result>
</soap:Body>
</soap:Envelope>