Re: How to parse a textfile ?
Re: How to parse a textfile ?
- Subject: Re: How to parse a textfile ?
- From: Emmanuel <email@hidden>
- Date: Wed, 29 Sep 2004 17:33:03 +0200
At 12:35 AM -0500 29/09/04, Joseph Weaks wrote:
Ok, how about anyone want to take a stab at the format of a data
file I need to parse? I've changed the subject matter for this
example to try and make the structure easier to understand. Here is
a sample excerpt from a data file:
California = 3
Rhode Island Really an island?
Texas Friendship state? = 8
Dallas
Grassy noll
State Fair
Houston
Austin = 3
Memorial stadium
Barton Springs
San Antonio = 2
Please, Joe, use XML.
Here is a proposition for some regexp which will make a XML - there
are many options, I went the fastest track. You still have to make
new "place" nodes when there is none.
--- untested
set x to "[your text here]"
set x1 to change " = ([0-9]+)" into "
<count>\\1</count>" in x with regexp
set x2 to change "([^ ]) (.*)$" into "\\1
<comment>\\2</comment>" in x1 with regexp
set x3 to change "^ ([^ ].*)$" into "</state>
<state name=\"\\1\">" in x2 with regexp
set x4 to change "^ ([^ ].*)$" into "
<place>\\1</place>" in x3 with regexp
set x5 to change "^ ([^ ].*)$" into "
<site>\\1</site>" in x4 with regexp
set x6 to "<joedb>" & return & (text 10 thru -1 of x5) & return &
"</state>" & return & "</joedb>"
set thexml to XMLOpen x6
-------------------
Emmanuel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden