Solved

Parsing XML response. in ASP.

Posted on 2003-11-06
4
407 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

19 Experts available now in Live!

Get 1:1 Help Now