Search results
This PHP code demonstrates how to read an XML file with CDATA by replacing the CDATA tags with placeholders before parsing and then restoring them in the parsed XML. The code also checks if the XML file exists and is readable before loading it.
13 lip 2011 · Use replace CDATA before parsing PHP DOM element after that you can get the innerXml or innerHtml: str_replace(array('<\![CDATA[',']]>'), '', $xml);
We do a lot of XML parsing at work using DOMDocument (php.net/manual/en/class.domdocument.php). It works just fine in handling CDATA. Give that a short or post a little more code for us to see how you're working with SimpleXML. You're probably not accessing it correctly.
This example works: <?php $xml = simplexml_load_file('file.xml', NULL, LIBXML_NOCDATA); $description = $xml->xpath("//item[@title='0x|Beschrijving']"); var_dump($description); ?> Here's the output:
PHP: How to handle <![CDATA[ with SimpleXMLElement? You can use the addCData() method of the SimpleXMLElement class to add a CDATA section to an XML element. For example:
28 cze 2024 · An XML Parser is a program that translates XML an XML document into a DOM tree-structure like document. CDATA is used to ignore special characters when parsing XML documents. PHP uses the simplexml_load_file to read XML documents and return the results as a numeric array
CDATA (meaning character data) is used for different but related purposes in the SGML and XML markup languages. The term CDATA is used for textual data that should not be parsed by an XML parser. The characters "<" and "&" are not allowed within XML elements.