Thread: Creating XML/KML documents from single tables

Creating XML/KML documents from single tables

From
"William Temperley"
Date:
Hi
I would be most grateful if someone could help me create an xml doc in the form:

<root>
  <layer name = 'x1'>
    <marker id="35"
class="1"><Point><coordinates>-3.04,53.56,0</coordinates></Point></marker>
    <marker id="35"
class="4"><Point><coordinates>-2.04,55.56,0</coordinates></Point></marker>
  </layer>
  <layer name = 'x2'>
    <marker id="35"
class="3"><Point><coordinates>-3.44,57.56,0</coordinates></Point></marker>
  </layer>
</root>

This will be created from a single table of point geometries where
each belongs to a layer, e.g. x1 or x2 etc. The layer a geometry
belongs to is stored in a varchar column called layername.

Creating the marker tags is easily done using the query:
# select xmlelement(name marker, xmlattributes(gid as id, typeid as
class), askml(the_geom)) from poi

Or creating a list of layers is also simple:
#select xmlelement(name layer, xmlattributes(layername as name)) from
poi group by layername

However I cannot work out how to insert more than one child node into
a layer element.

Thanks

Will T

Re: Creating XML/KML documents from single tables

From
"Pavel Stehule"
Date:
Hello

you have to use xmlagg function

Regards
Pavel Stehule

On 02/01/2008, William Temperley <willtemperley@gmail.com> wrote:
> Hi
> I would be most grateful if someone could help me create an xml doc in the form:
>
> <root>
>   <layer name = 'x1'>
>     <marker id="35"
> class="1"><Point><coordinates>-3.04,53.56,0</coordinates></Point></marker>
>     <marker id="35"
> class="4"><Point><coordinates>-2.04,55.56,0</coordinates></Point></marker>
>   </layer>
>   <layer name = 'x2'>
>     <marker id="35"
> class="3"><Point><coordinates>-3.44,57.56,0</coordinates></Point></marker>
>   </layer>
> </root>
>
> This will be created from a single table of point geometries where
> each belongs to a layer, e.g. x1 or x2 etc. The layer a geometry
> belongs to is stored in a varchar column called layername.
>
> Creating the marker tags is easily done using the query:
> # select xmlelement(name marker, xmlattributes(gid as id, typeid as
> class), askml(the_geom)) from poi
>
> Or creating a list of layers is also simple:
> #select xmlelement(name layer, xmlattributes(layername as name)) from
> poi group by layername
>
> However I cannot work out how to insert more than one child node into
> a layer element.
>
> Thanks
>
> Will T
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                http://archives.postgresql.org/
>