Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using IXMLHTTPRequest

35 views
Skip to first unread message

Alex Worrell

unread,
Aug 24, 2001, 6:18:17 AM8/24/01
to
I have been experimenting with the IXMLHTTPRequest interface and
have hit a stumbling block. I can perform an Open and a Send, and
I can query the responseText to see the valid XML retrieved from the
server, but I cannot work out how to use the responseXML property.

According to the SDK the responseXML property returns an
IDispatch, but this has no obvious use in parsing XML. I tried
casting this to a DOMDocument30 interface and querying the xml
property but nothing was returned.

My question is this: does anyone know what this property should
be cast to and how to use it.

Thanks

Alex


Howard Moon

unread,
Aug 24, 2001, 8:41:07 AM8/24/01
to
Alex,
Isn't DOMDocument30 part of the new MSXML3.DLL? IXMLHTTPRequest was
replaced in that library with just IXMLHTTP. If you're using
IXMLHTTPRequest, then a document is just IXMLDOMDocument, I think.
I haven't tried it...I always just use another DOM object and call loadXML
on it using the responseText as the parameter. Then I can manipulate that
DOM object's XML however I like.
-Howard


Alex Worrell

unread,
Aug 24, 2001, 10:33:53 AM8/24/01
to
Hi Howard

Thanks for the reply.

> Isn't DOMDocument30 part of the new MSXML3.DLL? IXMLHTTPRequest was
> replaced in that library with just IXMLHTTP.

I am using msxml3.dll for the interfaces and the xmlsdk30.chm help file for
reference.
There is no IXMLHTTP but there is an XMLHTTP which is just a redefinition of
IXMLHTTPRequest.

> If you're using IXMLHTTPRequest, then a document is just IXMLDOMDocument,
I think.
> I haven't tried it...I always just use another DOM object and call
loadXML
> on it using the responseText as the parameter. Then I can manipulate that
> DOM object's XML however I like.
> -Howard

I have also tried the loadXML, which works fine, but it seemed that if the
HTTPRequest
object had already parsed the XML it would be silly to parse it a second
time in another
DOM object, that is why I was hoping for information on how to use it. I
also assumed
that it would be an IXMLDocument, but casting it to that produced no
meaningful result.

Alex


Howard Moon

unread,
Aug 24, 2001, 2:05:17 PM8/24/01
to
Sorry...my mistake. It's the Coclass whose name changed. It went from
CoXMLHTTPRequest to just CoXMLHTTP. I just assumed the inteface name
changed, too. I found out I was wrong when I recompiled today. (Doh!)
Sorry about the misinformation. Does the updated MSDN Library site describe
the responseXML any better?
-Howard


Craig Murphy

unread,
Aug 25, 2001, 8:19:41 PM8/25/01
to
"Howard Moon" <hm...@landstar.com> wrote in message news:3b86975e_1@dnews...

> Sorry about the misinformation. Does the updated MSDN Library site
describe
> the responseXML any better?

Here's an example that uses XMLHTTP and demos how responseXML is used.

It's an old example that compiles under D4/D5, but the interfaces are the
same...

HTH
--Craig

procedure TfrmSOAP.btnExecuteClick(Sender: TObject);
var soapRequest,
soapResponse : DOMDocument;

httpOb : IXMLHTTPRequest;

nodeEnvelope,
nodeBody,
nodeMethod : IXMLDOMNode;

smn, s : string;

sServer : String;
bStrMethod, bstrUrl, varASync, bStrUser, bStrPassword : OleVariant;
sXML : String;

begin
//sServer := 'http://localhost/echoTest.asp';

if cbEndpoint.Checked then
sServer := edit7.text
else
sServer := 'http://localhost/soap/calcxslt.asp';

bStrMethod := 'POST';
bstrUrl := sServer;
varAsync := false;
bStrUser := '';
bStrPassword :='';
httpOb := CoXMLHTTP.Create; //CreateObject("Microsoft.XMLHTTP");
httpOb.Open(bStrMethod, bstrUrl, varASync, bStrUser, bStrPassword);

s:= '<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope">';
s:=s+'<SOAP-ENV:Body>';
s:=s+' <m:' + edtMethod.Text +'
xmlns:m="uuid:361C5CDE-FC66-4B17-A2C1-EB221DEFFD66">';
s:=s+' <pt1>';
s:=s+' <x>'+edit3.text+'</x>';
s:=s+' <y>'+edit4.text+'</y>';
s:=s+' </pt1>';
s:=s+' <pt2>';
s:=s+' <x>'+edit5.text+'</x>';
s:=s+' <y>'+edit6.text+'</y>';
s:=s+' </pt2>';
s:=s+' </m:' + edtMethod.Text +'>';
s:=s+'</SOAP-ENV:Body>';
s:=s+'</SOAP-ENV:Envelope>';

// Prepare the http request header...
httpOb.setRequestHeader('Content-Type','text/xml');

smn := 'uuid:361C5CDE-FC66-4B17-A2C1-EB221DEFFD66#';
smn := smn + edtMethod.Text;
httpOb.setRequestHeader ( 'SOAPAction', smn );

mRequest.text:=s;

// Send the request...
httpOb.send(s);

mResponse.text:=httpOb.ResponseText;

// Process the response...
soapResponse := CoDOMDocument.Create;
soapResponse.async:=false;
soapResponse.Load(httpOb.ResponseXml);

nodeEnvelope := soapResponse.childNodes[1];
nodeBody := nodeEnvelope.firstChild;
nodeMethod := nodeBody.firstChild;

if nodeMethod.baseName <> 'Fault' then begin
edit1.text:=nodeMethod.firstChild.selectSingleNode('x').text;
edit2.text:=nodeMethod.firstChild.selectSingleNode('y').text;
end;
end;

Alex Worrell

unread,
Aug 28, 2001, 11:28:36 AM8/28/01
to
Hi Craig

I have tried this and it does not seem to work properly. In my test project
I
have an object called http which is an IXMLHTTPRequest and doc which
is a DOMDocument30. Once I have done http.send('') the
http.responseText contains valid xml. If I do
doc.loadXML(http.responseText)
I get a result of true and the doc contains my xml document. However, if I
try doc.load(http.responseXML) I get a result of false and the
doc.parseError.reason gives the following: "XML document must have a top
level element."

So the question now is, why is it that loadXML works with the responseText
property, but load does not work with the responseXML property?

My response definitely has a top level element, so the only thing I can
think
that might (but shouldn't) cause a problem is the "<?xml version='1.0' ?>"


"Craig Murphy" <cr...@isleofjuraDOTdemon.co.uk> wrote in message
news:3b88407a_1@dnews...

Craig Murphy

unread,
Aug 29, 2001, 9:05:03 AM8/29/01
to
"Alex Worrell" <alex.w...@wsatkins.com> wrote in message
news:3b8ca4bc$1_1@dnews...

> have an object called http which is an IXMLHTTPRequest and doc which
> is a DOMDocument30. Once I have done http.send('') the
> http.responseText contains valid xml. If I do
> doc.loadXML(http.responseText)
> I get a result of true and the doc contains my xml document. However, if
I
> try doc.load(http.responseXML) I get a result of false and the
> doc.parseError.reason gives the following: "XML document must have a top
> level element."

Have you set the Content-Type for the response?

Rgs
--Craig


0 new messages