Jump to content

djburner

New Members
  • Posts

    3
  • Joined

  • Last visited

djburner's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi @Badger, I've change the snippet as I think you told me to do, but now is not doing anything. I know how to work with Javascript pretty well, but in PHP I'm just a total rookie, sorry if I do something really off the line. <?php $xml = simplexml_load_file("menu.xml"); $sxe = new SimpleXMLElement($xml->asXML()); $disenoItem = $sxe->addChild("disenoItem"); $disenoItem->addChild("name", "Ed Doe"); $disenoItem->addChild("age", "30"); saveXMLFile($xml, $sxe); function saveXMLFile($filename, $xml) { $dom = dom_import_simplexml($xml)->ownerDocument; $dom->formatOutput = true; $dom->save(menu.xml); // I used both (menu.xml) as well ($filename) but neither seems to work } ?> Hope you can see what is wrong in this approach. Thank you fro your time and help guys. Greetings.
  2. @Cainj Hi man, thanks for your snippet, it does look preety good, but I have some problems with it. My code looks like this: <?php $xml = simplexml_load_file("menu.xml"); $sxe = new SimpleXMLElement($xml->asXML()); $disenoItem = $sxe->addChild("disenoItem"); $disenoItem->addChild("name", "Ed Doe"); $disenoItem->addChild("age", "30"); saveXMLFile($xml, $sxe); function saveXMLFile($filename, $xml) { $dom = dom_import_simplexml($xml)->ownerDocument; $dom->formatOutput = true; $fh = fopen($filename,'w'); fwrite($fh,$dom->saveXML()); fclose($fh); } ?> What am I doing wrong, actually the FTP trows this error: TypeError: items[x][0] is undefined[] Thanks if you can check how I used your snippet in order to spot out the problem. I only delete the world "function" from your snippet right here: // $sxe->asXML("myXml.xml"); dont need this line function saveXMLFile($xml, $sxe); //I changed the above sentence into this: saveXMLFile($xml, $sxe); //Cause I think It was an error in your snippet, am I right? Greetings and thanks in advance for any futher help on this issue.
  3. Hi there, I was working in a XML file that I need to be updated by PHP, my problem is that using this snippet: <?php $xml = simplexml_load_file("myXml.xml"); $sxe = new SimpleXMLElement($xml->asXML()); $user = $sxe->addChild("user"); $user->addChild("name", "Ed Doe"); $user->addChild("age", "34"); $sxe->asXML("myXml.xml"); ?> After the php has run the XML has actuallly the updated information but here comes the catch: If I open the file in the browser like http://...myXml.xml the estructure does look great, indent spaces, breaks and all like in this form: <user> <name>Ed Doe</name> <age>34</age> </user> But when I try to see it in dreamweaver or another editor, the XML updated information does appear like a single line without any breaks like: <user><name>Ed Doe</name><age>34</age></user> Which is really going to get really messy when more data is updated since every entry as new user just extends the long single line. How could I add this indent spaces using PHP? Is there a way like: $myItem ->addChild("age", "34", <br/>); Hope anyone could give me a hand on this one. Greetings and thanks in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.