i have this script: <script type="text/javascript"> var xmlDoc=loadXMLDoc("login.xml"); var x=xmlDoc.getElementsByTagName('name'); for (i=0;i<x.length;i++) { if( x.childNodes[0].nodeValue=='<?php echo $_POST["name"]; ?>' ) { location="eggrafi_error5.html"; } } x=xmlDoc.documentElement; var name = xmlDoc.createElement('name','<?php echo $_POST["name"]; ?>'); var password = xmlDoc.createElement('password','<?php echo $_POST["password"]; ?>'); var new_user=xmlDoc.createElement('users'); new_user.appendChild(name); new_user.appendChild(password); x.appendChild(new_user); xmlDoc.save("login.xml"); </script> the login.xml is like that: <login><users> <name>george</name> <password>123456</password> </name> </login> my problem is that the only command that doesn;t work is the last one: xmlDoc.save("login.xml"); i can't save the xml file.... is sth wrong? the function loadXMLDoc is the above: function loadXMLDoc(dname) { var xmlDoc; // code for IE if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } // code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { xmlDoc=document.implementation.createDocument("","",null); } else { alert('Your browser cannot handle this script'); } xmlDoc.async=false; xmlDoc.load(dname); return(xmlDoc); }
i saw a script from an exercise but it must be in php script... i thought it would be the same in javascript. generally how can i save my xml file in javascript? Can i manipulate my xml file with php? i tried to do that in php but i was confused with load and save functions. any good tutorial about the above? any easy script for example? i use this link for tutorial: http://w3schools.com/
It was an ASP script. http://www.w3schools.com/xml/xml_savedata.asp If your server supports PHP5 than you can use this function: <?php $myxmlstuff = '<?xml ... ?>'; file_put_contents('file.xml', $myxmlstuff); ?> PHP:
look at this script: <?php $xmlDoc = new DomDocument(); $xmlDoc->load('exhibitions.xml'); //Returns a list of elements with the given tag name:'EXS'. $exhibitions = $xmlDoc -> getElementsByTagName('EXS'); //Creates new elements with the given tag names. $name = $xmlDoc->createElement('NAME', $_POST["name"]); $type = $xmlDoc->createElement('TYPE', $_POST["type"]); $subj = $xmlDoc->createElement('SUBJ', $_POST["subject"]); $place = $xmlDoc->createElement('PLACE', $_POST["place"]); $date = $xmlDoc->createElement('DATE', $_POST["date"]); $price = $xmlDoc->createElement('PRICE', $_POST["price"]); $artists = $xmlDoc->createElement('ARTISTS', $_POST["artists"]); $descr = $xmlDoc->createElement('DESCR', $_POST["description"]); $newExh=$xmlDoc->createElement('EXH'); //Add a node to the end of the list of children of the parent node "newExh". $newExh->appendChild($name); $newExh->appendChild($type); $newExh->appendChild($subj); $newExh->appendChild($place); $newExh->appendChild($date); $newExh->appendChild($price); $newExh->appendChild($artists); $newExh->appendChild($descr); //Add a node to the end of the list of children of the parent node "exhibitions". $exhibitions->item(0)->appendChild($newExh); $xmlDoc -> save("exhibitions.xml"); ?> this is asp? it works fine anyway. in javascript how can i save? in your example $myxmlstuff = '<?xml ... ?>'; is like load? sorry for too much questions....
No, thats PHP. You can't do file I/O in javascript. No, thats just a variable that has some example xml code.
and sth else $myxmlstuff = '<?xml ... ?>'; is there any function who loads and save from an xml file and not from a variable, in php of course?