Classic Asp - VBscript - how to handle XML parsing error

Microsoft Windows
Post Reply
1011010101010111001
Posts: 5
Joined: 2021-Oct-28, 4:06 pm

Classic Asp - VBscript - how to handle XML parsing error

Post by 1011010101010111001 »

I suck at VBscript. I'm making a Classic ASP page. (yeah yeah... 'its old', 'you should use something else'.... now that we have acknowledged that...)

I have no idea how to handle the error I'm getting gracefully.

Here is an example of the XML file data:

Code: Select all

<PDFlib>
    <PDF id="001">1</PDF>
    <PDF id="002">2</PDF>
    <PDF id="003">3</PDF>
</PDFlib>
Here is the code from ASP file:

Code: Select all

XML_Path = "//PDFlib/PDF[@id='002']"
Get_PDF_URL = objXML.selectSingleNode(XML_Path).text
"Get_PDF_URL = objXML.selectSingleNode(XML_Path).text" works fine, as long as the node exists. No shock there, but it throws a "438 - VBscript runtime error: Object doesn't support this property or method" error if you select a node that doesn't exist. I have tried for the last two hours to find a way to handle the error gracefully and I just can't figure it out right now.

Help me please! I'm so frustrated lol. (Please and thank you)
Post Reply