1

I have the XML file that contains some html entities in node content. Example:

...
<node>node&apos;s content</node>
...

When I load file by SimpleXML (using simplexml_load_file method), node content is being converted automatically to node's content

When I specify LIBXML_NOENT in simplexml_load_file - nothing happens, HTML entities still be parsed.

How to save original node content?

Meadow Lizard
  • 330
  • 2
  • 7
  • 19
  • Unless you specify the `LIBXML_NOENT` HTML entities shouldn't be parsed. Can you show more code? – Julien Lachal Jun 23 '17 at 14:31
  • I think you may be misunderstanding how entities work, and what they represent - the string content of that element *is* "node's content", the `'` is just how that's written into the XML. If you output the element back as XML, you'll see the `'` again. See also [this answer](https://stackoverflow.com/questions/13979582/php-simplexml-decoding-entities-in-cdata/13981917#13981917) to a somewhat related question. – IMSoP Jun 27 '17 at 09:39

1 Answers1

-2

You can add a parameter to simplexml_load_file() that keeps it from substituting HTML entities. See http://php.net/manual/en/libxml.constants.php.

SimpleXMLElement xml = simplexml_load_file("myFile", "SimpleXMLElement", LIBXML_NOENT(0));
sorayadragon
  • 1,087
  • 7
  • 21