Re: Simple question on simplexml
| From: | Jochem Maas | Date: | Fri, 06 Apr 2007 15:36:27 +0000 |
| Subject: | Re: Simple question on simplexml | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-252167@lists.php.net to get a copy of this message | ||
there is this:
http://php.net/manual/en/function.simplexml-element-addChild.php
which will allow adding of string data (so you won't be needing to
create the new SimpleXMLElement object as per your example below).
obviously you will have to first load tghe complete xml document
into simplexml using one of the following:
http://php.net/manual/en/function.simplexml-load-file.php
http://php.net/manual/en/function.simplexml-load-string.php
Timothy Murphy wrote:
> I have a catalog in XML format:
> <?xml version="1.0" encoding="iso-8859-1" ?>
> <catalog>
> <book>
> ...
> <book>
> <book>
> ...
> <book>
> ...
> </catalog>
>
> Now I want to add another book,
> which I have as a SimpleXMLElement:
>
> $book = new SimpleXMLElement($string);
>
> where $string reads
> <book>
> ...
> <book>
>
> Can I add this new entry to the catalog
> using SimpleXML functions,
> or do I have to introduce a DOMDocument?
>
> As may be obvious, I am very new to PHP programming;
> and advice or suggestions gratefully received.
>