There is such XML code, while parsing with the usual simplexml, this is lost " <user_data><!--[CDATA[https://steamcommunity.com/tradeoffer/new/?partner=131823210&amp;token=z1ih7YeC]]--></user_data> "what can I do?

 <digiseller.response><retval>0</retval><retdesc></retdesc><id_seller>123321</id_seller><unique_code>321123</unique_code><inv>213213</inv><id_goods>1931072</id_goods><amount>1</amount><type_curr>WMR</type_curr><date_pay>08.05.2015 11:40:33</date_pay><email>superdooker@gmail.com</email><cnt_goods>1</cnt_goods><options><option id="6151"><name>Test</name><user_data><!--[CDATA[https://steamcommunity.com/tradeoffer/new/?partner=131823210&amp;token=z1ih7YeC]]--></user_data></option><option id="6152"><name>    </name><user_data><!--[CDATA[https://steamcommunity.com/tradeoffer/new/?partner=131823210&amp;token=z1ih7YeC]]--></user_data></option><option id="6153"><name>    2</name><user_data><!--[CDATA[https://steamcommunity.com/tradeoffer/new/?partner=131823210&amp;token=z1ih7YeC]]--></user_data></option><option id="6154"><name>Test2</name><user_data><!--[CDATA[https://steamcommunity.com/tradeoffer/new/?partner=131823210&amp;token=z1ih7YeC]]--></user_data></option></options></digiseller.response> 
  • <! - and -> try to remove - GrayHoax
  • 2
    To begin with - to issue CDATA correctly (now you have this usual comment) - user6550

1 answer 1

A properly formed CDATA section should look like this.

 <![CDATA[https://steamcommunity.com/tradeoffer/new/?partner=131823210&amp;token=z1ih7YeC]]> 

you have this section commented out

 <!--[CDATA[https://steamcommunity.com/tradeoffer/new/?partner=131823210&amp;token=z1ih7YeC]]--> 

You can extract comments and comments from the XML file, but simplexml does not allow this. To solve the problem will have to act through the extension xml and XPath

 <?php $xml = '<digiseller.response>...</digiseller.response>'; $dom = new DOMDocument(); $dom->loadXML($xml); $xpath = new DOMXpath($dom); $comments = $xpath->query('//options/option/user_data/comment()'); foreach($comments as $value) { echo substr(str_replace('[CDATA[', '', $value->data), 0, -2).'<br />'; }