joos Posted August 22, 2007 Share Posted August 22, 2007 Help I have tried doing this using both the object and XML UDF but to no avail. I want to open an xml file Func ReadIt () Fileopen "path\Filename.xml" CheckforNodeInXMLFile "<NodeName>" If Node not there then exit Else If node is there (true) then continue CloseFile EndFunc Here is the XMLFile <?xml version="1.0" encoding="utf-8"?> <configinfo> <shop> <shop name="ShopOne" /> <shop name="ShopTwo" /> <shop name="ShopThree" /> </shop> <service> <!-- The default service has been changed at this time ** Only add this back in if needed ** <service name="Default" security="disabled" /> --> <service name="ServiceOne" /> <service name="ServiceTwo" /> <service name="ServiceThree" /> <service name="ServiceFour" /> <service name="ServiceFive" /> <service name="ServiceSix" /> </service> </configinfo> I am trying to find out if the <service> node is there. I have a program which writes this if it is successful. Any pointer or help will be a great help as the little hair I have left is slowly being pulled out Thanks Joe Link to comment Share on other sites More sharing options...
Zedna Posted August 22, 2007 Share Posted August 22, 2007 Search for XML in Examples and look at these scripts. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
weaponx Posted August 22, 2007 Share Posted August 22, 2007 All you want to know is is if the <service> node exists? Not if it actually has subnodes? Link to comment Share on other sites More sharing options...
weaponx Posted August 22, 2007 Share Posted August 22, 2007 Make sure you use eltorros' excellent XML UDF found here: http://www.autoitscript.com/forum/index.ph...amp;hl=xml++comThis will throw a message box stating if <service> was found or not:#include <_XMLDomWrapper.au3> $sXMLFile = "test.xml" $result = _XMLFileOpen($sXMLFile) If $result = 0 Then MsgBox(0,"", "Error opening " & $sXMLFile) Exit EndIf $sXPath = "configinfo/service" $nodeArray = _XMLSelectNodes($sXPath) if $nodeArray[0] > 0 Then MsgBox(0,"", "Service node found") Else MsgBox(0,"", "Service node NOT found") EndIf Link to comment Share on other sites More sharing options...
joos Posted August 22, 2007 Author Share Posted August 22, 2007 All you want to know is is if the <service> node exists? Not if it actually has subnodes?Yes just that.I have now opened the file and got each line in it$sfile = FileOpen("Filename", 0); Check if file opened for reading OK if not bomb outIf $sfile = -1 Then MsgBox(0, "Error", "Unable to open file.") ExitEndIfWhile 1 $sline = FileReadLine($sfile) If @error = -1 Then ExitLoop ; Do a string in string check for the <service> $iRoleCheck = StringInStr($sline, "<service>") If $iRoleCheck = "3" Then $itest = 1 EndIfWendFileClose($sfile)Not the best way and not reading the file as an XML file but this will give me the result i need at this time, however, not the way in which I wanted to do it. If the XML route would be better then I will keep plugging away.Thanks for the help.Joe Link to comment Share on other sites More sharing options...
weaponx Posted August 22, 2007 Share Posted August 22, 2007 I gave you what you need, just change $sXMLFile = "test.xml" to the name of you xml file. Link to comment Share on other sites More sharing options...
joos Posted August 22, 2007 Author Share Posted August 22, 2007 I gave you what you need, just change $sXMLFile = "test.xml" to the name of you xml file.Sorry weaponx did not see that when I answered. Thanks Joe Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now