Results 1 to 3 of 3

Thread: What if Xml file not found?

  1. #1

    Thread Starter
    Addicted Member wernerh's Avatar
    Join Date
    Sep 2000
    Posts
    170

    What if Xml file not found?

    Hi, here is my asp code:

    set xml = Server.CreateObject("Microsoft.XMLDOM")
    xml.async = false
    xml.load(server.MapPath("XML/WES.xml"))

    My Question is: how can I stop a error display if the xml file is not found, there might not always be a xml file, and then nothing must happen.

    also:

    set objNode = xml.SelectSingleNode("employee_details[user_defined_id='0001']")

    How do I test to see if the singlenode is found. If it is not found nothing must happen, but at the moment if it is not found I recieve errors.

    Please help

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    VBScript has pretty weak error handling, but that would be how to do it. You could also possibly use the FSO to check for file existance first.

    Code:
    set xml = Server.CreateObject("Microsoft.XMLDOM")
    xml.async = false
    On Error Resume Next
    xml.load(server.MapPath("XML/WES.xml"))
    If Err Then
    'handle error
    End If
    On Error Goto 0 'turn error handling off again, if you wish
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    I'm not sure that this applies to what you are doing but here is how to open an XML file.

    VB Code:
    1. XMLdoc.Load strTargetFile
    2.    
    3.     If XMLdoc.parseError.errorCode = 0 Then
    4.         If XMLdoc.readyState = 4 Then
    5.             ' It's OK
    6.         End If
    7.     Else
    8.         Err.Description = XMLdoc.parseError.reason & vbCrLf & _
    9.         "Line: " & XMLdoc.parseError.Line & vbCrLf & _
    10.         "XML: " & XMLdoc.parseError.srcText
    11.         ' Do some sort of error-handeling here using err.description
    12.     End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width