Re: Problem with string that contains XML-tags

[email protected] ("Rense Klinkenberg")
Newsgroups php.xml.dev
Message-ID <[email protected]>
You probably didn't set the "deep" parameter to true when calling
importNode. I had forgotten it either when making the following example ;-)

<?php

// Build main document
$dom1 = new domDocument;
$dom1->loadxml('<?xml version="1.0"?><root><sub /></root>');


// Build document to be imported
$dom2 = new domDocument;
$dom2->loadxml('<?xml version="1.0"?><root><importedNode><sub_importedNode
foo="bar" /></importedNode></root>');


// Import $dom2 root node to $dom1
// NOTE for the second parameter: If true, recursively import the subtree
under
// the specified node; if false, import only the node itself
$importedNode = $dom1->importNode($dom2->documentElement, true);

// Append the imported node to $dom1
$dom1->documentElement->appendChild($importedNode);

// Display the result
echo htmlspecialchars($dom1->saveXML());

?>

This code produces the expected result:
<?xml version="1.0"?>
<root><sub/><root><importedNode><sub_importedNode
foo="bar"/></importedNode></root></root>

I think that's the behaviour you were looking for.

</Rense>

"Christian Weyer" <[email protected]> wrote in message
news:[email protected]...
> Okay I understand what you i should do. But i have problems with :)
because
> this W3C-document isn't easy to read and understand and some functions are
> not implemented in php-dom. so could you give me a code example?
>
> I tried the this:
> Create a Document for the string
> Create the Document to to import the string
>
> Then I tried to get the node which represents the string in the import
> document, but i was not able to get the whole node with all subnodes and
all
> texts in it .. so an example would be great.
>
> thanks, chris.
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.