views:

155

answers:

3

I can't seem to find any decent info about this on the web. Any advice?

+3  A: 

I would use the DOM API that has been part of the core since 5. For an XML string $xml, you can build a DOM object with

$dom = new DOMDocument();
$dom->loadXML($xml);

Manipulate it with the rest of the DOM API, defined at http://uk.php.net/DOM

Adam Wright
A: 

And when you need to inject it back into some other DOM (like your HTML page) you can export it again using the $dom->saveXML() method. The problem however is that it also exports an xml header (it's even worse for the saveHTML version). To get rid of that use this:

$xml = $dom->saveXML();
$xml = substr( $xml, strlen( "<?xml version=\"1.0\"?>" ) );
A: 

If the input is HTML, use the loadHTML method. Be ware that the input has to be valid code, so you might want to pipe it through html tidy first.

troelskn