Page 1 of 1

write xml to specified node

Posted: Thu Jun 10, 2010 12:00 am
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!

Re: write xml to specified node

Posted: Thu Jun 10, 2010 3:40 am
by markusn00b
You can use XPath to grab the XML element you want. Then you simply SimpleXMLElement::addChild()

Mark.