Re: XML?

From: "Gavin M(dot) Roy" <gmr(at)justsportsusa(dot)com>
To: Bjorn T Johansen <btj(at)havleik(dot)no>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: XML?
Date: 2003-08-08 05:24:37
Message-ID: 3F333415.4090400@justsportsusa.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Here's some PHP code I use to do just that:

<xml version="1.0">
<?php
function returnRecord($resultid, $row, $level) {
$prepend = "";
for ( $y = 0; $y < $level; $y++ )
$prepend .= "\t";

$record = $prepend . "<RECORD>\n";
for ( $y = 0; $y < pg_NumFields($resultid); $y++ ) {
$record .= $prepend . "\t<" . pg_FieldName($resultid, $y) . ">";
$data = Trim(pg_Result($resultid, $row, $y));
$data = ereg_replace("&", "&amp;", $data);
$record .= $data;
$record .= "</" . pg_FieldName($resultid, $y) . ">\n";
}
$record .= $prepend . "</RECORD>\n";
return $record;
}

$conn = pg_Connect("my database connect string");
$result = pg_Query($conn, "SELECT * FROM MY_TABLE;");
$returnData = "";
$rows = pg_NumRows($result);
for ( $y = 0; $y < $rows; $y++ )
$returnData .= returnRecord($result, $y, 1);
pg_FreeResult($result);
pg_Close($conn);
?>
</xml>

Hope this helps,

Gavin

Bjorn T Johansen wrote:

>I need to convert recordsets to XML, is there an automatic way to do this
>in PostgreSQL or a tool I can use? Or do I have to code this manually?
>
>
>Regards,
>
>BTJ
>
>
>-----------------------------------------------------------------------------------------------
>Bjørn T Johansen (BSc,MNIF)
>Executive Manager
>btj(at)havleik(dot)no Havleik Consulting
>Phone : +47 67 54 15 17 Conradisvei 4
>Fax : +47 67 54 13 91 N-1338 Sandvika
>Cellular : +47 926 93 298 http://www.havleik.no
>-----------------------------------------------------------------------------------------------
>"The stickers on the side of the box said "Supported Platforms: Windows
>98, Windows NT 4.0,
>Windows 2000 or better", so clearly Linux was a supported platform."
>-----------------------------------------------------------------------------------------------
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>

In response to

  • XML? at 2003-08-08 05:07:42 from Bjorn T Johansen

Responses

  • Re: XML? at 2003-08-08 05:29:20 from Bjorn T Johansen
  • Re: XML? at 2003-08-08 05:31:42 from Gavin M. Roy

Browse pgsql-general by date

  From Date Subject
Next Message Bjorn T Johansen 2003-08-08 05:29:20 Re: XML?
Previous Message Bjorn T Johansen 2003-08-08 05:07:42 XML?