Generate XML string from FORM DATA based on XML schema

Generate XML string from FORM DATA based on XML schema

Post by Matt » Sun, 25 Apr 2004 04:07:12


I have 2 ASP pages. page1.asp will generate a xml string from form data
based on the XML schema, and then submit to page2.asp. My question is if ASP
has XML support, so that given form data, it will generate a XML string
based on the XML schema? Maybe I should use MSXML Parser?

The picture is like this:

Form Data, XML Schema -> ASP Function -> XML string

The problem is JavaScript doesn't have XML support.

Please advise. Thanks!!
 
 
 

Generate XML string from FORM DATA based on XML schema

Post by Joe Fawcet » Sun, 25 Apr 2004 18:04:47


If I have understood correctly you have a number of options, you can use
client side script to turn the form data into an xml string before posting
it to the processing asp page:

<form name="frmMain" method="post" action="secondpage.asp">
Forenames: <input type="text" name="txtForenames">
Surname:<input type="text" name="txtSurname">
<input type="hidden" name="txtXmlData">
<input type="button" value="submit" onclick="doSubmit();">
</form>
Then your JavaScript:
function doSubmit()
{
//Do validation
var sXml = "<data><forenames>" + document.frmMain.txtForenames.value +
"</forenames><surname>" + document.frmMain.txtSurname.value +
</surname></data>";
document.frmMain.txtXmlData.value += sXml;
document.frmMain.submit();
}
Now in your second page you load txtXmlData value into a parser.
You could also use the XmlHttp class that comes with mxsml parser version
3/4. There are plenty odf examples in the sdk. Now you can post a
domDocument to the server andload it directly into the parser:
oDomDoc.load(Request).

--
Joe (MVP - xml)