Jump to content

Using XML UDF - Error handling


Recommended Posts

I have been using the XML UDF successfully for sometime. I am now tring to add in error handling for some bad XML files I run into.

$oXmlDoc = _XML_CreateDOMDocument(Default)
    _XML_Load($oXmlDoc,$sFileXML)  ;<== ENTER XML FILE PATH HERE
    If @error Then
;        ConsoleWrite(StringFormat("_XML_load error - @error = %s", @error) & @CRLF)
;        ConsoleWrite("-" & $sFileXML & @CRLF)
        Exit -1
    EndIf
    ConsoleWrite("-" & $sFileXML & @CRLF)

    ;If no specified nodes exist, log error and exit
    If Not _XML_NodeExists($oXmlDoc, "//Property") Then
;        ConsoleWrite("No specified nodes exist" & @CRLF)
        Exit -1
    EndIf

    ;Get number of Property nodes
    $oProperties = _XML_SelectNodes($oXmlDoc,"//Property/Data")
   $iNodeCount = @extended
    $oParents = $oXmlDoc.SelectSingleNode("//Property[@Name='Parents']/Data")

There are no error upto this point. The XML file I am trying to handle has a Data node but when I try to

$sParam = StringSplit($oParents.text, ";")

I get a fatal error (requested action on object failed). How can I test for the problem before I try to do the string split? I tried using @error, and testing $oParents but no luck.

Appreciate any tips.

Link to comment
Share on other sites

Can you provide a short script, with test xml data, that reproduces the error? 

Link to comment
Share on other sites

If IsObj($oParents) Then
    $sParam = StringSplit($oParents.text, ";")
EndIf

You can also put in an error handler.  Do a forum search for AutoIt.Error

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...