Re: Interaction between SimpleXML & DOM



Lorenzo De Tomasi wrote:

$contentNode = $dom->importNode([$page->content->asXML()],
[?]);//I don't understand how to output the full tree under <content>
element in xml file. I have tried with childNodes, but it doesn't
work...

// Get list of all <content> elements in $page.
$contentNodes = $page->getElementsByTagName('content');

// Get first such <content> element. (There is probably only one.)
$contentNode = $contentNodes->item(0);

// For each child of <content>...
foreach ($contentNode->childNodes as $pageKid)
{
// Import it into $dom
$domKid = $dom->importNode($pageKid, 1);

// Add the imported node as a child of $body.
$body->appendChild($domKid);
}

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 21 days, 15:57.]

Bottled Water
http://tobyinkster.co.uk/blog/2008/02/18/bottled-water/
.



Relevant Pages