[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: ANNOUNCE: New release of X-Tract
Hi, Ashutosh -- You don't need XMLScript or anything special do what you're asking... Just write some Javscript functions; here's an example to get you started. The code below uses an invisible form as a container to XML-ify the elements of another form. To use it, set the "submit" method of your form to the submitXMLdata() function... <SCRIPT language="Javascript"> function o_tag(objElement,strTag) { objElement.value += "<" + strTag + ">"; } function c_tag(objElement,strTag) { o_tag(objElement,"/"+strTag); } function submitXMLdata(formFrom,formTo) { var objElement = window.document.forms[formTo].elements[0]; // put your XML declaration below objElement.value = ""; // write the document element o_tag(objElement,"formdata"); // loop through the form elements for (var i=0;i<window.document.forms[formForm].elements.length;i++) { var objFoo = window.document.forms[formForm].elements[i]; o_tag(objFoo.name); switch (objFoo) { case "text": objElement.value += objFoo.value; break; case "select-one": objElement.value += objFoo.options[objFoo.selectedIndex].value; break; // And you can write some routines here to // loop over the selected indices in a // multi-select, or to handle checkbox values, // or... } c_tag(objElement,objFoo.name); } // close the document element c_tag(objElement,"formdata"); // send it on its way toForm.submit(); } </SCRIPT> <form name="unseen" action="targeturl.cgi" method="POST"> <input type="HIDDEN" name="XMLdata"> </form> Or, depeding on your exact needs, you can do a myriad of other things. Unless you need some real firepower on the client-side, there is no reason to use anything other than Javascript. The only reason to use Javascript is that the client can perform operations that would otherwise burden the server (if you have a lot of traffic or get a denial of service attack...). (In this case, you're going to be parsing a form submission either way, whether it's a straight form or XML wrapped in a form, so I don't see the benefits of XML-i-fying the data on the client.) - Paul *************************************************************************** This is xml-dev, the mailing list for XML developers. To unsubscribe, mailto:majordomo@x...&BODY=unsubscribe%20xml-dev List archives are available at http://xml.org/archives/xml-dev/threads.html ***************************************************************************
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|