Re: Parsing a text file
Re: Parsing a text file
- Subject: Re: Parsing a text file
- From: Frank Miedreich <email@hidden>
- Date: Wed, 22 Aug 2001 10:16:15 +0200
At 19:00 Uhr -0400 21.08.2001, Matthew Fischer wrote:
I have some text files which are saved individual e-mail messages.
Each of them has various types of header information, followed by
the following:
<password>a unique password of varying length</password>
<username>a unique username of varying length</username>
<message>some more unique text of varying length.
This one could be more then one line.
Blah, blah, blah.</message>
None of the unique passwords, usernames or messages contain the
characters > or <, however the header text most likely will.
I'm trying to use applescript to parse out the three items into
properties, however I'm missing the boat. This is the last thing I
tried, which gives me a chunk of the file, but not the part I'm
looking for:
open for access file "FishbookG4HD:Desktop Folder:b7a82d6b"
read file "FishbookG4HD:Desktop Folder:b7a82d6b" until "<password>"
set thePass to read file "FishbookG4HD:Desktop Folder:b7a82d6b"
before "</password>" as text
close access file "FishbookG4HD:Desktop Folder:b7a82d6b"
display dialog thePass
Are the until and before treated as complete strings, or as a list
of characters? I thought the second read starts where the first left
off until you close the access, but I guess I'm really missing the
boat on this one.
What's the best way to retrive the text that is in between (and not
including) the three pairs of tags?
Thanks in advance for any help, and please CC me since I'm on the digest.
Matt
Hi,
I do not know haw read before is supposed to work, but I see two possibilities:
given the file above you can do this:
set tags to {"password", "username", "message"}
set msg to ""
set f to open for access file "FishbookG4HD:Desktop Folder:b7a82d6b"
repeat with tag in tags
set s1 to "<" & tag & ">" as string
set s2 to "</" & tag & ">" as string
read f until s1
set c to read f until s2
set c to characters (count s1) thru -2 of c
set msg to msg & tag & "=" & c & return
end repeat
close access f
display dialog msg
the other way (the proper way IMO) is to use late night's XML tools.
cheers, Frank
--
Frank Miedreich
Mozquito Technologies AG
Check out our new Website at
http://www.mozquito.com/