Error handling in XML

sushant

Usenet Archive
Joined
Jun 22, 2002
Messages
33
Reaction score
0
Hi,

I have to read a part of document & transoform into HTML using xsl. To read the document i am using selectsinglenode with XPATH & code runs fine.

+++++++++++++++++++++++++
Function viewDetail(strXMLFile, strXSLFile, strEMail)
Dim objXML
Dim objNode
Dim objXSL
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load(strXMLFile)
'Get the XML record that you wish to view by calling the 'SelectSingleNode method and passing in the e-mail address of the 'contact. Set objNode = objXML.SelectSingleNode("rolodex/contact[field/field_value='" & strEMail & "']") set objXSL = Server.CreateObject("Microsoft.XMLDOM") objXSL.async = false objXSL.load(strXSLFile) Response.Write(objNode.transformNode(objXSL)) End Function +++++++++++++++++++++++++++

But problems occur when strEmail value brings wrong data which is not available in XML data file. In that case, it displays asp error. Is there any way to handle the error as objXML doesnt return anything? Please let me know if there is any.

thanks,
hungrymind
 

john.nance

Usenet Archive
Joined
May 28, 2004
Messages
2
Reaction score
0
Hi Sushant

There's loads of ways of approaching this but one common way is just to check the return value using "isNothing"

So your code could be

Set objNode =
objXML.SelectSingleNode("rolodex/contact[field/field_value='" & strEMail & "']")

if isNothing(objNode) then
Response.Write("Nothing")
else
set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = false
objXSL.load(strXSLFile)
Response.Write(objNode.transformNode(objXSL))
end if

You can also use isNull in the same way.

Good luck

John

sushant wrote:

'Get the XML record that you wish to view by calling the 'SelectSingleNode method and passing in the e-mail address of the 'contact.
Set objNode =
objXML.SelectSingleNode("rolodex/contact[field/field_value='"
& strEMail & "']")
set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = false
objXSL.load(strXSLFile)
Response.Write(objNode.transformNode(objXSL))
End Function
+++++++++++++++++++++++++++

But problems occur when strEmail value brings wrong data which is not available in XML data file. In that case, it displays asp error. Is there any way to handle the error as objXML doesnt return anything? Please let me know if there is any.
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top