[xsde-users] Parsing - Getting Super Data

Mark Easton mark63 at azurebell.co.nz
Sat Sep 27 06:56:25 EDT 2008


Many thanks Boris,

I think I will follow through on the first technique and put the data in to
data structures and then process these at the site level.

Cheers
Mark 

> -----Original Message-----
> From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
> Sent: Friday, September 26, 2008 8:19 PM
> To: Mark Easton
> Cc: xsde-users at codesynthesis.com
> Subject: Re: [xsde-users] Parsing - Getting Super Data
> 
> Hi Mark,
> 
> Mark Easton <mark63 at azurebell.co.nz> writes:
> 
> > I have a site which is made up of areas. I.e. SO have a 
> site type and 
> > an area type.
> > 
> > <site>
> > 	<id>1</id>
> > 	<name>Auckland</name>
> > 	<area>
> > 		<id>1</id>
> > 		<name>Onehunga</name>
> > 	</area>
> > </site>
> > 
> > 
> > So in my areapimpl class how do I access the id from 
> sitepimpl (ie I 
> > need the site_id for my area record)?
> 
> There is no built-in mechanism for this kind of access since 
> the data normally flows from inner parsers to the outer ones. 
> The recommended way to handle this is to propagate the 
> information from inner parsers to the point where you have 
> all the parts necessary to process it. In your case, to 
> handle area you need the area data itself as well as the site 
> id. The place where all this information can be made 
> conveniently available is the site_pimpl::area() callback. 
> Here is an outline of the site_pimpl class:
> 
> // In the type map, map XML Schema type for area to this struct.
> //
> //
> struct area_data
> {
>   int id;
>   string name;
> };
> 
> 
> struct site_pimpl: size_pskel
> {
> 
>   virtual void id (int v)
>   {
>     site_id = v;
>   }
> 
>   virtual void area (const area_data& ad)
>   {
>     // ad and site_id contain all the information we need.
>   }
> 
> private:
>   int site_id;
> };
> 
> struct area_pimpl: area_pskel
> {
>   
>   virtual void id (int v)
>   {
>     ad.id = v;
>   }
> 
>   virtual void name (const string& s)
>   {
>     ad.name = s;
>   }
>   
>   virtual area_data post_area ()
>   {
>     return ad;
>   }
> 
> private:
>   area_data ad;
> };
> 
> Another alternative which is not as clean but can be useful if you
> can't afford to copy, say, the name string to a temporary struct
> is to arrange a connection between site_pimpl and area_pimpl:
> 
> 
> struct site_pimpl: size_pskel
> {
>   virtual void id (int v)
>   {
>     site_id = v;
>   }
> 
>   int site_id;
> };
> 
> struct area_pimpl: area_pskel
> {  
>   area_pimpl (site_pimpl& s)
>     : site_p (s)
>   {
>   }
> 
>   virtual void id (int v)
>   {
>     // site_p.site_id conatins site id
>   }
> 
>   virtual void name (const string& s)
>   {
>     // site_p.site_id conatins site id
>   }
>  
> private:
>   site_pimpl& site_p;
> };
> 
> Boris
> 



More information about the xsde-users mailing list