Jump to content

See if an XML node exists


Recommended Posts

How can I see if a node exists in an xml file?

Here's the code I currently have:

CODE
Func EQ2XML()

$XMLobject = ObjCreate("MSXML.DOMDocument")

$FileSystem = ObjCreate("Scripting.FileSystemObject")

$strTempFileName = $EQ2File&"\lpconfig.xml"

$file = FileExists($strTempFileName)

;This function removes the user name from the config file to prevent someone from seeing it in the user field

;It does this by searching the xml file (lpconfig.xml) for the word "respart"

;When it finds it, it completely removes the child object from the file, not just the word respart

If $file = 1 Then

$XMLobject.Load($strTempFileName)

$oXmlroot = $XMLobject.documentElement

$LogFile = $FileSystem.OpenTextFile($strTempFileName)

If @error <> 0 Then

TrayTip("Error", "There was an error opening "& $strTempFileName, 10, 3)

EndIf

$nClearRecs = $oXmlroot.selectNodes("/LaunchPadConfig/eq2")

For $recs In $nClearRecs

If $recs.selectSingleNode("CurrentUser").text = "respart" Then

$xPath = $oXmlroot.selectSingleNode("/LaunchPadConfig/eq2/CurrentUser")

$xPath.parentNode.removeChild($xPath)

EndIf

$XMLobject.save($strTempFileName)

Next

EndIf

EndFunc

My code keeps bombing on the line below since the 'CurrentUser' node doesn't exist.

CODE
If $recs.selectSingleNode("CurrentUser").text = "respart" Then

How can I have my code basically say "If the node 'CurrentUser' doesn't exist, exit the loop."?

Link to comment
Share on other sites

  • 1 month later...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...