|
Posted by Jeremy on 10/11/06 23:52
uidzer0 wrote:
> Hey everyone,
>
> I am trying to figure out how to import an external xml file into a
> current document at a certain location within the document ie:
>
> Here is my main xml:
>
> <books>
> <book>
> <title>1</title>
> <author>a</author>
> </book>
> <book>
> <title>2</title>
> <author>b</author>
> </book>
> <book>
> <title>3</title>
> <author>c</author>
> </book>
> </book>
>
>
> And here is the xml to be imported:
>
> <book>
> <title>new</title>
> <author>new author</author>
> </book>
>
> I would like to import this right after the first book entry (after 1,
> before 2), can anyone point me in the right direction here?
>
> Thanks!
>
> Ben
>
Are you using DOM for this? If so,
$doc1 = new DOMDocument("main.xml");
$doc2 = new DOMDocument("new.xml");
$newBook = $doc1->importNode($doc2->documentElement, true);
$doc1->documentElement->insertBefore($newBook,
$doc1->documentElement->childNodes->item(2));
That oughtta do it. http://www.php.net/dom for more info.
Jeremy
Navigation:
[Reply to this message]
|