XML DOM: commit/save to xml file
I have done the parsing of the form by document.getElementByID().value (which works well), and loaded and edited my XML document with the *.appendChild() method. However, nothing happens to the XML file that was loaded.
I occurred to me that maybe I had to 'commit' my changes, but I cannot find the correct method to do so on the w3c schools. I have found a micro$oft extention to the XML DOM that is called *.save() that I suppose would do the job. I am no fan of micro$oft however, and having made the rest of my site standards-compliant, it feels like crap having to use *one* MS extension.
Bottom line: Is there a standards-compliant way of saving an XML document to a file on the server?
I crufted together something in PHP which did the job.
Working on same project requirement
You look like you were working on the same problem of committing the xml file that I've been working on. I wanted to POST the xmlDoc once I'd modified text nodes but have discovered you can't commit it the server without something in between.
Could you share the PHP script you put together? Also the way you posted the xml file changes to the PHP script.
Sure. This is the script I threw together. I do not pretend to have any understanding of PHP, but it does what it was supposed to do. For the actual presentation of the database I have written a small piece of XSLT. You can find more information on www.w3schools.com.
And, yeah; the identifiers are in Swedish. Sorry
$doc = new DOMDocument();
$doc->formatOutput = true;
$musiker = $doc->createElement ( "musiker" );
$namn = $doc->createElement( "namn" );
$musiker->appendChild( $namn );
$instrument = $doc->createElement( "instrument" );
$musiker->appendChild( $instrument );
$status = $doc->createElement( "status" );
$kommentar = $doc->createElement( "kommentar" );
$tid = $doc->createElement( "tid" );
$doc->createTextNode(strftime("%Y-%m-%d, %T") )
$musiker->appendChild( $tid );
$r = $doc->documentElement;
$r->appendChild( $musiker );
echo $doc->save( "rhelg.xml" );
Thanks so much. That's really helpful.
I build all my web sites using xml and xslt. I'm now extending things by gradually adding AJAX features.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread