Regarding additions to XML via PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aunk
    New Member
    • Apr 2016
    • 14

    Regarding additions to XML via PHP

    I'm developing a web app. Right now it's going by pretty easily. Unfortunately, I'm having trouble writing to an XML file and it's beginning to get hairy over here. So, my question is this: How can I take this code and make it add to my already started XML file?

    Code:
    $newNode = "<allusers></allusers>";
    $xmlRoot = simplexml_import_dom($xmlDoc);
    foreach ($parr as $nodes => $vals) {
            $txt = "<" . $nodes . ">" . $vals . "</" . $nodes . ">\n";
    }
    $xmlRoot->addChild("<user>",$txt);
    echo $xmlRoot->asXML();
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    XML does not support innerHTML. so you have to add the tags one-by-one.
    Code:
    foreach ($parr as $nodes => $vals) {
        $parentNode->addChild($nodes, $vals);
    }

    Comment

    • aunk
      New Member
      • Apr 2016
      • 14

      #3
      Yea I figured that out last night writing the code, aft I'd asked this question. Thanks!

      Comment

      Working...