Re: Import data from XML file - Mailing list pgsql-general

From John R Pierce
Subject Re: Import data from XML file
Date
Msg-id 4A95653E.8080404@hogranch.com
Whole thread Raw
In response to Import data from XML file  (Erwin Brandstetter <brsaweda@gmail.com>)
List pgsql-general
Erwin Brandstetter wrote:
> Hi!
>
> How do you import data from an xml-file?
> For instance, if I have a file like this:
>
> <?xml version="1.0" encoding="utf-8"?>
>  <p_update>
>    <main_categories>
>      <main_category>
>        <main_category_name>Sonstiges</main_category_name>
>        <main_category_id>5</main_category_id>
>      </main_category>
>      <main_category>
>        <main_category_name>Buehne</main_category_name>
>       <main_category_id>2</main_category_id>
>     </main_category>
>     <main_category>
>       <main_category_name>Konzerte</main_category_name>
>       <main_category_id>1</main_category_id>
>     </main_category>
>   </main_categories>
>   <categories>
>     <category>
>       <category_name>Reggae</category_name>
>       <main_category_id>1</main_category_id>
>       <category_id>45</category_id>
>     </category>
>     <category>
>       <category_name>sonstige</category_name>
>       <main_category_id>5</main_category_id>
>       <category_id>44</category_id>
>     </category>
> </categories>
> </p_update>
>
>
> ... and I want a CSV file like this:
>
> main_category_name    main_category_id
> Sonstiges    5
> Buehne    2
>
> category_name    main_category_id   category_id
> Reggae    1    45
> sonstige    5    44
>
>
> Or is there a way to import directly into tables in a postgres
> database?
>

isn't it amazing how redundantly wordy XML is, yet it doesn't provide
sufficient information to perform this simple task without more knowlege
(for instance, there's no data types, but we sure know the name of the
fields as they are spelled out twice for each row!)




pgsql-general by date:

Previous
From: Erwin Brandstetter
Date:
Subject: Import data from XML file
Next
From: Edwin Plauchu
Date:
Subject: Re: Import data from XML file