Solved

Parsing XML response. in ASP.

Posted on 2003-11-06
4
398 Views
Last Modified: 2011-10-03
I am posting to an XML string as follows:

Set XMLRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
XMLRequest.open "POST", "http://gateway.textforce.net/sendsms.cfm", False
XMLRequest.SetRequestHeader "Host", "gateway.textforce.net"    
XMLRequest.SetRequestHeader "Connection", "Keep-Alive"
XMLRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
XMLRequest.send("xml=" & Server.URLEncode(xml))


The response I get I am trying to parse using the following code to get the StrRecipient and StrTransactionID values:

Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.loadXML(XMLRequest.responseXML.XML)
Set PathTempA = xmlDoc.selectSingleNode("SMSMessage/SMSMessageData")
Set PathTempB = xmlDoc.selectSingleNode("SMSMessage/SMSGateway")
StrRecipient = PathTempA.selectSingleNode("Recipient").text
StrTransactionID = PathTempB.selectSingleNode("TransactionID").text

All works fine until I try and insert an ampersand character in my post in the node named MessageText.  When it works, the XML response is:

  <?xml version="1.0" ?>
- <SMSMessage>
- <SMSAuthentication>
  <Username>xxx</Username>
  <Password>xxx</Password>
  </SMSAuthentication>
- <SMSMessageData>
  <Originator>TEXTCLEVER</Originator>
  <Recipient>xxx</Recipient>
  <MessageType>0</MessageType>
<MessageText>0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456780</MessageText>
  <ControlData />
  </SMSMessageData>
- <SMSGateway>
  <Response>00</Response>
  <TransactionID>6D2D1417-BF00-4852-98B4-A9EC130B7F96</TransactionID>
  <ErrorText />
  </SMSGateway>
  </SMSMessage>

When it fails , I get an error saying the 'PathTempA' Object not found.  When I click view source, the message says, 'The XML source file is unavailable for viewing'

Is there a differnet way to do this so that the response is returned correctly
0
Comment
Question by:videnda
4 Comments
 
LVL 15

Expert Comment

by:deighc
ID: 9702414
I don't really understand your question. You say the error occurs when you add an ampersand to your XML string, in which case you post a copy of that string so that we can look at it.

The problem is almost certain to be a character encoding issue. XML is very fussy about encoding. An ampersand should be encoded to &amp; and all other "funny" chars need to be encoded to &#[ascii char value];

Post a sample of your XML string and I'll see if I can help you more.
0
 

Author Comment

by:videnda
ID: 9730207
I have answered the question myself.

The responseXML.XML contained an ampersand, which caused an error.  I had to use responseText instead and replace the ampersand before loading the string in to the DOM object.

Thanks for you help.
0
 

Accepted Solution

by:
SpazMODic earned 0 total points
ID: 9755508
PAQed, with points refunded (50)

SpazMODic
EE Moderator
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now