write xml to specified node

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pullmand
Forum Newbie
Posts: 1
Joined: Wed Jun 09, 2010 11:55 pm

write xml to specified node

Post by pullmand »

Hey,

So I am currently working on CMS that will automate the process of creating an XML file with data from form inputs. I know how to read and write XML using SimpleXML and the DOM.

My question is...how do you write children to a specified node in a document? If possible, I'd prefer to do it with SimpleXML. For example I something like this:

Code: Select all

<?xml version="1.0"?>
<shell>
     <chapter id="01">
          <screen id="01">
               <background>...</background>
          </screen>
          <screen id="02" />
     </chapter>
</shell>
What I want to do is be able to append children to the screen node where the id="02". In addition, I will have to be able to append children to any number of screen nodes. There is not a set number of screen nodes per file. Any help would be awesome!
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: write xml to specified node

Post by markusn00b »

You can use XPath to grab the XML element you want. Then you simply SimpleXMLElement::addChild()

Mark.
Post Reply