[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: best way to generate form from xml+schema?
>At the moment, the only idea I have for that is > to give the cgi parameters names which reflect the xml > structure (eg not 'email', but > 'programItem:submitter:email'). Write the parameters to a > temporary file. Then use a stylesheet heavily dependent on > 'substring-after' functions to generate an xml file with > expanded versions of the parameters (eg <programItem> > <submitter> > <email>a@xxx</email> > </submitter> > </programItem> > Then read this into a second stylesheet which also reads in > the schema to generate the full xml file. Wow! I would suggest a liberal use of <div elements in your form that reflect your xml. Then instead of submitting the form as is you have an onsubmit function that wanders over your form constructing an xml string which you then post back to the server. Something like. <form name="x" onsubmit="post(this)"> <div name="xml_element_name"> <input type="text" name="xml_element_name" cjb:type="attribute" /> <input type="text" name="xml_element_name" cjb:type="text" /> <div name="xml_element_name"> <input type="text" name="xml_element_name" cjb:type="attribute" /> <input type="text" name="xml_element_name" cjb:type="text" /> </div> </div> </form> function post(obj){ var postString = wander(obj); var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); xmlhttp.Open("POST", "http://someplace", false); xmlhttp.Send(postString); } function wander(obj){ var retStr = ""; if (obj.tagName == "DIV"){ retStr += "<" + obj.name + " "; for (var i=0; i<obj.childNodes.length; i++){ if (obj.childNodes[i].tagName == "INPUT"){ if (obj.childNodes[i].getAttribute("cjb:type") == "attribute"){ retStr += obj.childNodes[i].name + "=" + obj.childNodes[i].value; }else{ retStr += ">" + obj.childNodes[i].value; } }else{ retStr += wander(obj.childNodes[i]); } } retStr += "</" + obj.name + ">"; } return retStr; } It would be a lot easier to use xslt and use the form.innerHTML as the input to the transform but the problem is that the innerHTML is nowhere near valid xml. Ciao Chris XML/XSL Portal http://www.bayes.co.uk/xml XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|