Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: XML data structure parsing in Mathematica 6 using patterns

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81621] Re: [mg81502] XML data structure parsing in Mathematica 6 using patterns
  • From: Daniel Flatin <dflatin at rcn.com>
  • Date: Sat, 29 Sep 2007 02:34:14 -0400 (EDT)
  • References: <21153656.1190833488110.JavaMail.root@m35> <op.ty94kdkbqu6oor@monster.gateway.2wire.net>

On Sep 26, 2007, at 16:58, DrMajorBob wrote:

> I can't WAIT to hear someone explain in what way the documentation  
> on this is totally clear!
>
> Until then, I can only observe that Help gives no examples in which  
> (as in your attempts) PatternSequence is the left-hand side of a  
> rule, or a pattern (in itself) to be matched. There are only  
> examples where PatternSequence is inclosed in List or f. (Those are  
> the only supported Heads, if I'm judging from Help alone, but I  
> suppose f means "any head".)

[ snip ]

> You wanted ONLY the time-pairs, which may require something like
>
> p = {___, a : ({_String, _String} ...),
>     PatternSequence[XMLElement["start-valid-time", _, {startT_}],
>      XMLElement["end-valid-time", _, {endT_}]],
>     b___} :> {a, {startT, endT}, b};
> timeBlock[[3]] //. p
>
> {{"2007-09-21T20:00:00-04:00",
>   "2007-09-22T08:00:00-04:00"}, {"2007-09-22T08:00:00-04:00",
>   "2007-09-22T20:00:00-04:00"}, {"2007-09-22T20:00:00-04:00",
>   "2007-09-23T08:00:00-04:00"}, {"2007-09-23T08:00:00-04:00",
>   "2007-09-23T20:00:00-04:00"}, {"2007-09-23T20:00:00-04:00",
>   "2007-09-24T08:00:00-04:00"}, {"2007-09-24T08:00:00-04:00",
>   "2007-09-24T20:00:00-04:00"}}
>
> All this seems to mean that PatternSequence[p1,p2] is not a  
> pattern, since you can't match anything with it. But anyhead 
> [PatternSequence[p1,p2]] IS a pattern.

That was exactly the insight I needed. Thanks! I also like Chris  
Chiasson's approach of naming the patterns. That will be useful since  
this is part of a larger parsing project.

> timeBlock /.
>  XMLElement[
>    "time-layout", _, {layoutKeyElement_,
>     dataElements :
>      PatternSequence[XMLElement["start-valid-time", __],
>        XMLElement["end-valid-time", __]] ..}] :>
>   Partition[{dataElements}[[All, 3, 1]], 2]

Dan




  • Prev by Date: Re: Problem with symbolic solution of a differential
  • Next by Date: Re: Alignment matrix Output
  • Previous by thread: Re: XML data structure parsing in Mathematica 6 using patterns
  • Next by thread: Higher order total derivatives