2

I'm trying to read anXML file using 'simplexml_load_file' and it works fine, except with one file that has these tags '',''. When I try to read this file, it fails like it was a blank file. Than I try to remove this character ':' and than it works...

Is there a better way to read this, without removing the ':' character?

here the XML

<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Header> <nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeAutorizacao"> <cUF>43</cUF> <versaoDados>3.10</versaoDados> </nfeCabecMsg> </soap:Header> <soap:Body> <nfeAutorizacaoLoteResult xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeAutorizacao"> <retEnviNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="3.10"> <tpAmb>2</tpAmb> <verAplic></verAplic> <cStat>104</cStat> <xMotivo>Lote processado</xMotivo> <cUF>43</cUF> <dhRecbto>2014-10-29T08:49:23-02:00</dhRecbto> <protNFe versao="3.10"> <infProt> <tpAmb>2</tpAmb> <verAplic></verAplic> <chNFe></chNFe> <dhRecbto>2014-10-29T08:49:23-02:00</dhRecbto> <nProt>143140001934763</nProt> <digVal></digVal> <cStat>100</cStat> <xMotivo>Autorizado o uso da NF-e</xMotivo> </infProt> </protNFe> </retEnviNFe> </nfeAutorizacaoLoteResult> </soap:Body> </soap:Envelope> 
4
  • Please format code & mark which tag is causing issues. Commented Oct 29, 2014 at 15:46
  • I need to read last tag <xMotivo> but i cannot open this XML by theses tags <soap:Envelope> Commented Oct 29, 2014 at 15:51
  • Why not use SoapClient class? php.net/manual/en/soapclient.soapclient Commented Oct 29, 2014 at 15:58
  • How should I use this to read an XML? I never use these classes before, can you show me an example? Commented Oct 29, 2014 at 16:01

2 Answers 2

0

In an XML file you have to escape special chars. Otherwise your XML syntax is broken.

http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

Other think perhaps the Request to fetch die XML is not in UTF-8.

Sign up to request clarification or add additional context in comments.

5 Comments

But this XML isn't made by me, I receive it from server return
Ok how do you fetch the file? Perhaps your encoding is not correct?
It is a return from server, I send my XML and the server send to me this XML. It is a financial system.
Yes but write your code how your send and get the XML file. When you do it with curl for example then you should set the correct encoding
I'm using a framework, I didn't set any encoding. My framework is nfephp from nfephp.org
0

This is duplicate question.

Read answers here:

parse a SOAP XML response with Namespaces using PHP

Parse soap response using PHP

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.