I have some XML response from the server, but they don't have a root element, because of that I can't parse them with the new SimpleXML, so I need to create a root element and then add all those xml to this one created root element
$res = bill_curl('GetAccounts'); //getting a list of accounts WITHOUT the <root> xml
$xml = new SimpleXMLElement("<root></root>"); // creating a root element
$xml->addChild($res); // adding to the <root> childrens
but the problem is:
1) the "<!--?xml version="1.0" encoding="UTF-8"?-->"
stays inside and the same is at the top of the document
2) got some symbols like "<", "/>" how to remove them?
Updated:
<document>
<answer>
<account>12345678</account>
<info>someinfo</info>
</answer>
<answer>
<account>23456789</account>
<info>some info</info>
</answer>
</document>
this is what i've got after string manipulation then I make:
$xml = new SimpleXMLElement($str);
and here I get an error of start and ending tags mismatching, what I am missing here?
I'm not particularly keen on the brittleness of this solution. However, it sounds like you you're integrating against a flawed API, so I would suggest some basic string manipulation to get what you want:
$str = '<?xml version="1.0" encoding="UTF-8"?><testing>2</testing><test2>1</test2>';
// the above was a test string to represent the results of the below:
$str = bill_curl('GetAccounts');
// Switch the search string below with the actual doctype you're getting from the API.
// It looks to have been commented out in your question which may or may not be the case.
$str = str_replace('<?xml version="1.0" encoding="UTF-8"?>', '', $str);
$str = '<root>'.$str.'</root>';
$xml = new SimpleXMLElement($str);
var_dump($xml);