We have an XML document:

<?xml version="1.0"?> <main> <metadata> <title><![CDATA[Title]]></title> <styles><![CDATA[On]]></styles> <script name="a"><![CDATA[Off]]></script> <script name="b"><![CDATA[On]]></script> </metadata> <data> <text><![CDATA[This is simple text for this data]]></text> <img><![CDATA[http://www.fullhdoboi.com/wallpapers/thumbs/6/kartinka-apelsiny-1885.jpg]]></img> <codes> <data_code><![CDATA[sH37Djcd]]></data_code> <document_code><![CDATA[lnbtyuJBTc11933774]]></document_code> </codes> </data> </main> 

There is a php code:

 $xml_file = simplexml_load_file($data); /// $data - наш XML документ /// Распечатка свойств объекта echo "<pre>"; print_r($xml_file); echo "</pre>"; /// Вывод script со значением атрибута (name) b echo $xml_file->metadata->script[1]; 
  1. I do not get when printing a data object from CDATA, how to fix it?
  2. As you can see there are two identical tags, but with different contents of the attribute, how to make it so that I can call not by index, but by key?
  • This is $xml_file = simplexml_load_file($data, 'SimpleXMLElement', LIBXML_NOCDATA); ? - Visman
  • @Visman Yes, I tried it, but when you display all the properties, the structure changes and attributes disappear ... by the way, you know nothing about the second question? - MaximPro

0