Re: XML to Postgres conversion

Поиск
Список
Период
Сортировка
От Mark O'Connor
Тема Re: XML to Postgres conversion
Дата
Msg-id 3D2D503B.9000301@tellcare.com
обсуждение исходный текст
Ответ на Re: XML to Postgres conversion  (Nathan Hill <cmsu_tech@yahoo.com>)
Список pgsql-general
This is just to demonstrate how XSLT can come to your rescue (You will
obviously have to adapt the approach).
The following stylesheet will generate a series of SQL inserts.

I use the sablotron XSLT transformer but really any suitable program
should work.

Regards,

MArk

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text"/>

<!--
Assumes the XML file has a series of Operating_system tags
-->
<xsl:template match="/">
   <xsl:apply-templates select="//Operating_system"/>
</xsl:template>

<!--
Generate a SQL INSERT for each "Operating_system" tag
-->
<xsl:template match="Operating_system">
   INSERT INTO computers (
     Name,
     Major_version,
     Minor_version,
     Build_number,
     Platform_ID,
     Additional_information,
     User_name,
     Boot_time,
     Registered_to,
     Registration_code
   VALUES (
     '<xsl:value-of select="Name"/>',
     '<xsl:value-of select="Major_version"/>',
     '<xsl:value-of select="Minor_version"/>',
     '<xsl:value-of select="Build_number"/>',
     '<xsl:value-of select="Platform_ID"/>',
     '<xsl:value-of select="Additional_information"/>',
     '<xsl:value-of select="User_name"/>',
     '<xsl:value-of select="Boot_time"/>',
     '<xsl:value-of select="Registered_to"/>',
     '<xsl:value-of select="Registration_code"/>');
</xsl:template>

</xsl:stylesheet>


Nathan Hill wrote:

> Here is a snippit of code from one of the xml files:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Computer>
>   <Created_on>2002/07/09 11:09:41</Created_on>
>   <Client_version>1.8.9</Client_version>


>   <General_info>


Please note that this tag is not closed!!!!


>     <Operating_system>
>       <Name>Microsoft Windows XP</Name>
>       <Major_version>5</Major_version>
>       <Minor_version>1</Minor_version>
>       <Build_number>2600</Build_number>
>       <Platform_ID>2</Platform_ID>
>
> <Additional_information></Additional_information>
>       <User_name>someone</User_name>
>       <Boot_time>07/09/2002 09:04:21</Boot_time>
>       <Registered_to>registered</Registered_to>
>
> <Registration_code>534574-345-7467453-74538</Registration_code>
>     </Operating_system>
> </Computer>
>


В списке pgsql-general по дате отправления:

Предыдущее
От: "Henrik Steffen"
Дата:
Сообщение: Re: Serious Crash last Friday
Следующее
От: "Agent155 Support"
Дата:
Сообщение: workaround for lack of REPLACE() function