Is there a way to extract the "innerHTML" of a SimpleXMLElement?
For example how would I get '<div><h1>Hello World</h1></div>'
out of the following XML Code using SimpleXMLElement:
<xml>
<body1>
<div><h1>Hello World</h1></div>
</body1>
<body2>
<div><h2>Goodby Moon</h2></div>
</body2>
</xml>
I read the documentation and all I came up with was $xml->body1->asXML();
.
It is almost the right solution but it also adds the root tag:
<body1>
<div><h1>Hello World</h1></div>
</body1>
Is it possible to skip the surrounding body1 tags?
Edit:
The xml might also look like this:
<xml>
<body1>
<div><h1>Hello World</h1></div>
<div><h1>Hello Moon</h1></div>
Some Text
</body1>
<body2>
<div><h2>Goodby Moon</h2></div>
</body2>
</xml>
As in: http://codepad.org/8ZuRYZOW
If you're sure it's a div
you're looking for :
$xml->body1[0]->div->asXML();
else
$xml->body1[0]->children()->asXML();
http://codepad.org/QUytim28 else http://codepad.org/hDt28BL6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With