Yesterday I had already a question to parsing an xml document in php. Now the parsing works kind of, but I only get everything in a string, not an object.
My code:
$xml = simplexml_load_file('file.xml');
debug($xml); // debug from CakePHP
Empty output, as I learned from my last post:
$xml = $xml->asXML();
debug($xml);
Now I only get the output as following:
I do get the XML code, but everything in a string with ->asXML(). How can I get everything as a XML object? I tried to use the string with simplexml_load_string($xml); but that just outputs the same as in the first screenshot.
Maybe there is a problem because the XML starts with <asx:abap></asx> (namespace)?
If you want, I can upload my XML so you can test it.
Edit 1
I realized, that the first two elements in my XML are namespaced (<asx:abap> and asx:values). As soon as I renamed them to asx only, everything worked fine.
Edit 2
Here my XML for you to test.


<asx:abap></asx:abap>with<asx></asx>, I get everything as an object. How can I fix that? The XMLs are generated by SAP and search/replace before parsing is not really a nice thing.object(SimpleXMLElement)- you just don't have the right debug function to view it - it looks like it's based onprint_r, which doesn't know how to display SimpleXMLElement objects properly. Try github.com/IMSoP/simplexml_debug