1

I have the following XML file

<?xml version="1.0" encoding="UTF-8"?>
<newsItem>
       <contentSet>
              <inlineXML contenttype="application/xhtml+xml">
                     <html xmlns="http://www.w3.org/1999/xhtml">
                            <div>
                                   <h1>St. Augustine Gold and Copper Limited: Update on Recent Corporate Developments</h1>
                               </div>
                      </html>
               </inlineXML>
       </contentSet>
</newsItem>

I want to get the value in using with the following code with no problem

if (file_exists('example.newsml')) {
    $xml = simplexml_load_file('example.newsml');

    $html= (string) $xml->{'contentSet'}->{'inlineXML'}->{'html'}->{'div'}->{'h1'};

    echo $html; 

} else {
    exit('Failed to open test.xml.');
}

I tried to get the html from the node but get empty result.

$content = (string) $xml->{'contentSet'}->{'inlineXML'}->{'html'};
echo $content;

Any suggestions?

Tester
  • 798
  • 2
  • 12
  • 32

1 Answers1

1

Just save the node as XML

echo $xml->contentSet->inlineXML->html->saveXml();

Output: https://eval.in/205477

<html xmlns="http://www.w3.org/1999/xhtml">
  <div>
    <h1>St. Augustine Gold and Copper Limited: Update on Recent Corporate Developments</h1>
  </div>
</html>
ThW
  • 19,120
  • 3
  • 22
  • 44