Re: Using SimpleXML



hwcowan@xxxxxxxxxxx wrote:
> 1. Add a new node / element.

You will need a bit of DOM for this:

// Create a simple xml document
$dom = new DomDocument;
$dom->loadXML('<root />');

// Create an element
$elem = $dom->createElement('child');

// Get the root node and append the new element
$root = $dom->documentElement;
$root->appendChild($elem);

// Continue processing with simplexml
$simple = simplexml_import_dom($dom);

See http://www.php.net/dom for more info.

> 2. Save my changes back to the XML file

http://www.php.net/manual/nl/function.simplexml-element-asxml.php


JW



.



Relevant Pages

  • Re: XML, Memory, DOM, VFP9
    ... > CursorToXML works fast because it's not using the DOM to generate the text ... > required is 2-3 times the XML size plus the amount of time it actually takes ... > You should look at using a SAX parser or put together your own XML document ... >> I am having a problem with xmltocursor. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Problem parsing namespaces with xml.dom.minidom
    ... It wouldn't need to conform to the official specifications of the DOM ... I need to be able to parse a namespace-using XML document ... into some kind of node tree, and then being able to query the tree to ...
    (comp.lang.python)
  • BIS/ICE & XML
    ... the other a .xml file (which I think is the resulting XML document). ... Kathy. ... Prev by Date: ...
    (comp.sys.unisys)
  • Re: Xerces c++ xml log
    ... the xml document when i'm doing the following instruction of code: ... the xerces return an xercesc::XMLException saying "Could not open ... then you can use DOM to serialize just one record instead of the ...
    (comp.text.xml)
  • Re: xml.xmldocument.load does it load document to memory?
    ... > I am making a simple app that groups files together by storing them into ... an xml document. ... It gets loaded into memory COMPLETE in an in-memory tree representation, ... DOM is supposed to work in general). ...
    (microsoft.public.dotnet.framework)