OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: ANNOUNCE: New release of X-Tract

[ Lists Home | Date Index | Thread Index ]
  • From: "Paul R. Brown" <prb@uic.edu>
  • To: <xml-dev@xml.org>
  • Date: Tue, 29 Feb 2000 21:22:30 -0600


(sent previously from incorrect address)

> I am looking out for a xml doc generator, at the
> client browser after client enters data in fields,
> that data i want to send to web server as xml doc
> can xml script be used for that purpose? or any
> other method you know of?


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@xml.org&BODY=unsubscribe%20xml-dev
List archives are available at http://xml.org/archives/xml-dev/threads.html
***************************************************************************




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS