2

I am using PHP SimpleXML to parse data in a file. Say for example I have the following XML content:

<?xml version="1.0" ?>
<root>
  <parent1>
    <child1>blah</child1>
    <child2>blah blah</child2>
  </parent1>
  <parent2>blah</parent2>
</root>

I basically want to get the actual raw content of the inside of a node. I.e. I need it to return the "innerXML" of parent1 just as text, tags and all. Having trouble getting PHP to do this. Help?

1 Answers1

0

For getting the exact content '<child1>blah</child1><child2>blah blah</child2>' as itself you better put them under <![CDATA[]]> Then you can get any thing inside that as iself.

xml should be like this::

<?xml version="1.0" ?>
<root>
  <parent1>
    <![CDATA[<child1>blah</child1>
    <child2>blah blah</child2>]]>
  </parent1>
  <parent2>blah</parent2>
</root>

Then

$xml = simplexml_load_string($xmlstring, 'SimpleXMLElement', LIBXML_NOCDATA);

$parent1 = $xml->parent1->asXml();
echo "<pre>";echo ($parent1);echo "<pre>";

This will output :

<child1>blah</child1>
<child2>blah blah</child2>