stefano Posted August 6, 2006 Share Posted August 6, 2006 I have a text file which is currently filled with a list of albums/artists: <artist>AC DC</artist><album>Back in Black</album> <artist>The Beatles</artist><album>Sgt. Pepper's Lonely Hearts Cl</album> <artist>The Beatles</artist><album>Abbey Road</album> <artist>Bob Dylan</artist><album>Great Woods 1993-09-13</album> <artist>Bumblefoot</artist><album>Hands</album> <artist>Buon Vecchio Charlie</artist><album>1971 - Buon Vecchio Charlie</album> <artist>Camel</artist><album>Mirage</album> I want to be able to parse the data in between the <artist> or <album> tags into a stored variable but I am having no luck so far. Can anyone recomend a method of doing so? The layout of the text file is adjustable, it does not have to be inbetween <artist> etc tags. Link to comment Share on other sites More sharing options...
Paulie Posted August 6, 2006 Share Posted August 6, 2006 I have a text file which is currently filled with a list of albums/artists: <artist>AC DC</artist><album>Back in Black</album> <artist>The Beatles</artist><album>Sgt. Pepper's Lonely Hearts Cl</album> <artist>The Beatles</artist><album>Abbey Road</album> <artist>Bob Dylan</artist><album>Great Woods 1993-09-13</album> <artist>Bumblefoot</artist><album>Hands</album> <artist>Buon Vecchio Charlie</artist><album>1971 - Buon Vecchio Charlie</album> <artist>Camel</artist><album>Mirage</album> I want to be able to parse the data in between the <artist> or <album> tags into a stored variable but I am having no luck so far. Can anyone recomend a method of doing so? The layout of the text file is adjustable, it does not have to be inbetween <artist> etc tags.You could do a stringSplit on the '<' sign then a "stringtrimleft" 7 characters Link to comment Share on other sites More sharing options...
/dev/null Posted August 6, 2006 Share Posted August 6, 2006 (edited) Can anyone recomend a method of doing so?StringRegExp() or search the forum for "+Microsoft +XMLDOM" if the file has a real XML structure.CheersKurt Edited August 6, 2006 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 6, 2006 Share Posted August 6, 2006 Hi, what about Func _StringBetween1($s_String, $s_Start = 0, $s_End = 0) $s_Start = StringInStr($s_String, $s_Start) + StringLen($s_Start) Return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End) - $s_Start) EndFunc ;==>_StringBetween1 oÝ÷ ÚÚºÚ"µÍ[ÈÔÔWÐ]ÙY[ ÌÍÜ×ÔÝ[Ë ÌÍÜ×ÔÝ ÌÍÜ×Ñ[ ÌÍÚWÔ]^HH NÈ ÌÍÚWÔ]^H]È[^HÙ[Ý[Y]HKÝÚÙHY][]ÈÝÝ[ ÌÍØWÐ^HHÝ[ÔYÑ^ ÌÍÜ×ÔÝ[Ë ÌÎNÊÎÌÎNÈ [È ÌÍÜ×ÔÝ [È ÌÎNÊJÊJÎÌÎNÈ [È ÌÍÜ×Ñ[ [È ÌÎNÊIÌÎNËÊBYÝÜ[Ý ÌÍÚWÔ]^H[Ð^J ÌÍØWÐ^JH[] ÌÍØWÐ^VÌBYÐ^J ÌÍØWÐ^JH[] ÌÍØWÐ^B[[ So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Paulie Posted August 6, 2006 Share Posted August 6, 2006 StringRegExp() or search the forum for "+Microsoft +XMLDOM" if the file has a real XML structure.CheersKurtMan i've been trying to find StrinRegExp in the helpfile all day and i don't thinks it's therecare to offer a crash course? Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 6, 2006 Share Posted August 6, 2006 Hi,go here http://www.autoitscript.com/autoit3/files/beta/autoit/and then undocumentated. There are several bugs in RegExp funcs, that is why they are out at the moment of beta.So long,Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
stefano Posted August 6, 2006 Author Share Posted August 6, 2006 Thanks everyone for your replies. You could do a stringSplit on the '<' sign then a "stringtrimleft" 7 charactersI'm assuming that returns the 7 characters after the <artist> tag, if so the problem with that is that some of the artists names are longer than 7 characters. Or am I missing something. StringRegExp() or search the forum for "+Microsoft +XMLDOM" if the file has a real XML structure. The text file is exactly as I posted, it kinda copies the xml structure. I have tried playing with this XML Wrapper but could not get it to work. what about Func _StringBetween1($s_String, $s_Start = 0, $s_End = 0) $s_Start = StringInStr($s_String, $s_Start) + StringLen($s_Start) Return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End) - $s_Start) EndFunc ;==>_StringBetween1 oÝ÷ ÚÚºÚ"µÍ[ÈÔÔWÐ]ÙY[ ÌÍÜ×ÔÝ[Ë ÌÍÜ×ÔÝ ÌÍÜ×Ñ[ ÌÍÚWÔ]^HH NÈ ÌÍÚWÔ]^H]È[^HÙ[Ý[Y]HKÝÚÙHY][]ÈÝÝ[ ÌÍØWÐ^HHÝ[ÔYÑ^ ÌÍÜ×ÔÝ[Ë ÌÎNÊÎÌÎNÈ [È ÌÍÜ×ÔÝ [È ÌÎNÊJÊJÎÌÎNÈ [È ÌÍÜ×Ñ[ [È ÌÎNÊIÌÎNËÊBYÝÜ[Ý ÌÍÚWÔ]^H[Ð^J ÌÍØWÐ^JH[] ÌÍØWÐ^VÌBYÐ^J ÌÍØWÐ^JH[] ÌÍØWÐ^B[[ That looks interesting, but I can't get that to work either. I'm kinda new to autoit. Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 6, 2006 Share Posted August 6, 2006 (edited) Hi, read the file into an Array with the func _FileReadToArray() Then build a loop and go through every line. Use this func (example for one line) $string ="<artist>AC DC</artist><album>Back in Black</album>" MsgBox(0,"_StringBetween1", "Artist: " & _StringBetween1($string,'<artist>', '</artist>') & @CRLF & "Album: " & _StringBetween1($string,'<album>', '</album>')) Func _StringBetween1($s_String, $s_Start = 0, $s_End = 0) $s_Start = StringInStr($s_String, $s_Start) + StringLen($s_Start) Return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End) - $s_Start) EndFunc ;==>_StringBetween1 So long, Mega Edited August 6, 2006 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 6, 2006 Moderators Share Posted August 6, 2006 (edited) Here run this with AutoIt Beta... And replace the txt file location or xml location with where ever it is.$TxtLocation = @DesktopDir & '\test.txt' $hFRead = FileRead($TxtLocation) $Artist = _SRE_BetweenEX($hFRead, '<artist>', '<') $Album = _SRE_BetweenEX($hFRead, '<album>', '<') For $iCount = 0 To UBound($Artist) - 1 MsgBox(64, 'Info:', 'Artist: ' & $Artist[$iCount] & @CR & 'Album: ' & $Album[$iCount]) Next Func _SRE_BetweenEX($s_String, $s_Start, $s_End, $iCase = 'i') If $iCase <> 'i' Then $iCase = '' $a_Array = StringRegExp($s_String, '(?' & $iCase & _ ':' & $s_Start & ')(.*?)(?' & $iCase & _ ':' & $s_End & ')', 3) If @extended & IsArray($a_Array) Then Return $a_Array Return SetError(1, 0, 0) EndFunc Edited August 6, 2006 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...
stefano Posted August 6, 2006 Author Share Posted August 6, 2006 Both work perfectly, thank you both so much. Link to comment Share on other sites More sharing options...
jefhal Posted August 6, 2006 Share Posted August 6, 2006 (edited) StringRegExp() or search the forum for "+Microsoft +XMLDOM" if the file has a real XML structure.$ans = StringRegExp($b,"(??: <artist>)(.+?)(?: </artist>))(??:<album>)(.+?)(?:</album>))",3) Edited August 10, 2006 by jefhal ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
/dev/null Posted August 6, 2006 Share Posted August 6, 2006 $ans = StringRegExp($b,"(??: <artist>)(.+?)(?: </artist>))(??:<album>)(.+?)(?:</album>))",3)Looks funny with the smileys "expanded" CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
jefhal Posted August 6, 2006 Share Posted August 6, 2006 Looks funny with the smileys "expanded" Yeah, and I tried three different ways of avoiding that from happening: quote/autoit/codeToo lazy to create a hyperlink... ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
Paulie Posted August 6, 2006 Share Posted August 6, 2006 Yeah, and I tried three different ways of avoiding that from happening: quote/autoit/codeToo lazy to create a hyperlink... Just uncheck the 'Enable Emoticons' Link to comment Share on other sites More sharing options...
jefhal Posted August 10, 2006 Share Posted August 10, 2006 Just uncheck the 'Enable Emoticons'Thanks, Paulie! Done. ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format 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