You are here: Re: DOM importNode « PHP Programming Language « IT news, forums, messages
Re: DOM importNode

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация