Solved

Parsing XML response. in ASP.

Posted on 2003-11-06
4
431 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

737 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