• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

ASP XML selectSingleNode problem

I'm having some trouble parsing an XML document I'm getting from my company's bank in response to a XML document I'm sending.  Both docs are transferring fine, and in fact if the transaction in the document I send is accepted (valid credit card), everything parses perfectly.  The prob is when the transaction is not accepted by the bank server (invalid credit card), and the document that's returned to me has different tags.

I'm using the selectSingleNode method to get the text from the correct tag, and it works perfectly when the tag is there.

Here is the offending VBScript line

------------------
AuthCode = xmlDocument.selectSingleNode("//Transaction//AuthCode").Text
------------------

A valid credit card will result in a return document with an AuthCode tag inside a Transaction tag, and the above code grabs the text from it perfectly.

An invalid credit credit card returns a document that does not possess the AuthCode tag, and I get the following error on the line number where I set AuthCode:

------------------
Microsoft VBScript runtime error '800a01a8'
Object required: 'xmlDocument.selectSingleNode(...)'
------------------

According to documentation at MSDN, selectSingleNode should return a null value when the pattern is not matched.  It is instead causing this error, which is making the capture of data from an invalid transaction impossible.

Have tried this as well:

------------------
AuthCode = Null
AuthCode = xmlDocument.selectSingleNode("//Transaction//AuthCode").Text

If AuthCode Is Null Then ...
------------------

Which merely return this on the line of the if statement:

------------------
Microsoft VBScript runtime error '800a01a8'

Object required
------------------

I have updated my Win2K server to have the .NET framework, as well as MDAC 2.7, to no avail.

Any ideas?
0
ultmast
Asked:
ultmast
1 Solution
 
mikkolsoftCommented:
Probably you have to grab the node to see if it exists before you ask for its text, like:

set AuthCodeObj = xmlDocument.selectSingleNode("//Transaction//AuthCode")
if not AuthCodeObj is nothing then
'Sucess
  AuthCode = AuthCodeObj.text
else
'Failed

end if

Mikkol
0
 
ultmastAuthor Commented:
It appears to work perfectly.  I had never tried to "set" the object without referencing the text associated with it.

Was almost to the point of having to redo the entire thing in JScript.

Thank you much.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now