xml - PHP DomDocument appendChild to end of root -


i've got xml formatted so

<things>   <thing>     <name>foo</name>     <id>1</id>   </thing>   <thing>     <name>bar</name>     <id>2</id>   </thing> </things> 

and i've created new <thing> element info form. when $dom->appendchild($newthing), it's appended end of document, after </things>.

   <things>      <thing>         <name>foo</name>         <id>1</id>       </thing>       <thing>         <name>bar</name>         <id>2</id>       </thing>     </things>     <thing>        <name>bar</name>        <id>2</id>     </thing> 

obviously want new element child of root element, not after it. how do that?

$dom->documentelement->appendchild($newthing); 

from php manual:

documentelement
convenience attribute allows direct access child node document element of document.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -