Sign in to follow this  
Followers 0
buymeapc

See if an XML node exists

2 posts in this topic

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."?

Share this post


Link to post
Share on other sites



What does this return

$recs.selectSingleNode("CurrentUser")


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
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
Sign in to follow this  
Followers 0