[thelist] POSTing XML from an ASP page?

Marcus Andersson marcus at bristav.se
Wed May 12 05:43:53 CDT 2004


Tom Dell'Aringa wrote:
> --- Scott Dexter <dexilalolai at yahoo.com> wrote:
> 
> 
>>>What I have to do from there is build XML from that data and then
>>>again POST it to one of our XML interfaces we have.
>>
>>How are these interfaces accessed? HTTP? (D)COM? ftp? email?
> 
> 
> HTTP
> 
> 
>>>1. How do I get my form data into XML (I'm fairly familiar with
>>
>>XML
>>
>>I'd tackle it brute force, since there really isn't any facility in
>>ASP to output it for you: loop through the form variables and
>>create your XML by hand.
> 
> 
> Can you be more specific? Should I simply be outputting and
> concatenating lines like:
> 
> somevar = "<foo>value1</foo>"
> somevar = "<foo2>value2</foo2>" (rough example)
> 
I would really advise against that if you by mean to just build a 
string. Why? Because there might come in characters that must handled 
the correct way to work with XML services and you will almost always end 
with errors if you try to do the encoding by hand.

>>>2. Once I have that XML (I assume sitting in a variable) how do I
>>>then POST it?
>>
>>Again, how are the XML interfaces consumed in a "normal" situation?
> 
> 
> Normally they are consumed via HTTP if I understand you (and them
> heh) correctly. I was told I could just post it to
> HTTP://blah_blah_blah
>

Use XmlHttp.

So my proposal is the following (I do it in javascript since my VB):

var doc = Server.CreateObject("Msxml2.DOMDocument");
var root = doc.createElement("root"); // whatever root should be named
doc.documentElement = root;

// create the rest of the object, if you need more on this I will help you

// time to send the stuff
var xmlHttp = Server.CreateObject("Msxml2.XMLHTTP");
// you can change to post if you want and the false is to turn async off
xmlHttp.Open("POST", "http://yoururlhere", false);
xmlHttp.Send(doc);

//done!

// you can get the response from your other server via responseXML
var xmlRes = xmlHttp.responseXML;

You can set a lot of headers etc. if needed on the XmlHttp object

/Marcus



More information about the thelist mailing list