saldous Posted February 21, 2007 Share Posted February 21, 2007 (edited) I'm trying to parse a file on my hard drive to find some text within it. The file I am trying to read from is an XML file, I don't need to make any changes to the XML, just capture some data from it. I'm unsure if to first open the file in RAW (4) or READ (0) mode? (Read is the only one that seems to do something in my test)Secondly, I read the file in, then to check it read the correct thing I wanted to simply display what was read on the screen, but this is not returning what I expected, it returns the following:ÿB<My code is below, is anyone able to tell me where I've gone wrong? (the xml file only have about 450 characters within it)Thank you:CODE#include <String.au3>$file = FileOpen("C:\Data.xml",0) If $file = -1 Then Msgbox(0,"","Error Opening File") EndIf $line = FileRead ($file)Msgbox(0, "Line Read","" & $line)$sStart = "<VersionNumber>"$sEnd = "</VersionNumber>"$version = _StringBetween ($line, $sStart, $sEnd) IF $version = 0 Then Msgbox(0,"","Error Getting Version Number") Else EndIf MsgBox (0,"","The version number is:" & $version)FileClose("C:\Data.xml") Edited February 21, 2007 by saldous Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 21, 2007 Moderators Share Posted February 21, 2007 Is this an XML file or an EXE file? Anyway, if the file is in Unicode, you'll need to translate it to ansii. Without the actual file to test, I can only speculate. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
saldous Posted February 21, 2007 Author Share Posted February 21, 2007 Is this an XML file or an EXE file?Anyway, if the file is in Unicode, you'll need to translate it to ansii. Without the actual file to test, I can only speculate.The file is XML, I can open it in NotePad and read the plain text fine. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 21, 2007 Moderators Share Posted February 21, 2007 The file is XML, I can open it in NotePad and read the plain text fine.Well, yes of course you can. You can open just about anything up in notepad and read it in notepad .But what type of file is it, is it saved as Unicode, UTF-8, or ANSII? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
saldous Posted February 21, 2007 Author Share Posted February 21, 2007 Well, yes of course you can. You can open just about anything up in notepad and read it in notepad .But what type of file is it, is it saved as Unicode, UTF-8, or ANSII?I have to admit I don't know how to work this out, I'm happy to email the file to you if you want to PM me your address?than you for trying to help me. Link to comment Share on other sites More sharing options...
saldous Posted February 21, 2007 Author Share Posted February 21, 2007 (edited) ok, ignore that, I've found a basic way of solving the file type and reading it in by doing the following: CODE RunWait('cmd /c type "' & $fileOriginal & '" > "' & $fileNew & '"') My script can now read in the text correctly. Yippeee. Edited February 21, 2007 by saldous Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 21, 2007 Moderators Share Posted February 21, 2007 (edited) I have to admit I don't know how to work this out, I'm happy to email the file to you if you want to PM me your address?than you for trying to help me.Actually you can PM me the file if you like or upload it here (probably smarter considering the kids are getting ready for school)... as I said in the PM, not much for going out of my way.ok, ignore that, I've found a basic way of solving the file type and reading it in by doing the following:CODE RunWait('cmd /c type "' & $fileOriginal & '" > "' & $fileNew & '"')My script can now read in the text correctly. Yippeee.Good, as I suspected it was probably in Unicode Nice to see someone find their own solution, and actually post that solution Edited February 21, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
saldous Posted February 21, 2007 Author Share Posted February 21, 2007 Is there another way to convert it from Unicode though? The only problem with my solution is that there is a very brief DOS box window that appears on the screen, I'd rather it didn't do this, but no major issue if not. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 21, 2007 Moderators Share Posted February 21, 2007 Is there another way to convert it from Unicode though? The only problem with my solution is that there is a very brief DOS box window that appears on the screen, I'd rather it didn't do this, but no major issue if not.RunWait('cmd /c type "' & $fileOriginal & '" > "' & $fileNew & '"', '', @SW_HIDE) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
saldous Posted February 21, 2007 Author Share Posted February 21, 2007 Perfect! Link to comment Share on other sites More sharing options...
hirak Posted February 15, 2011 Share Posted February 15, 2011 Perfect! hello saldousafter editin with RunWait('cmd /c type "' & $fileOriginal & '" > "' & $fileNew & '"', '', @SW_HIDE)can u post ur script to read xml file 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