• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to parse a textfile ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >How to parse a textfile ? (From: Stefan Eriksson <email@hidden>)
 >Re: How to parse a textfile ? (From: Graff <email@hidden>)
 >Re: How to parse a textfile ? (From: Joseph Weaks <email@hidden>)

  • Prev by Date: sort order
  • Next by Date: Re: GUI screen capture?
  • Previous by thread: Re: How to parse a textfile ?
  • Next by thread: Re: How to parse a textfile ?
  • Index(es):
    • Date
    • Thread