Re: Working with XML.

From: Theo Galanakis <Theo(dot)Galanakis(at)lonelyplanet(dot)com(dot)au>
To: 'George Weaver' <gweaver(at)shaw(dot)ca>
Cc: "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Working with XML.
Date: 2005-02-15 03:46:59
Message-ID: D1444817B78AB546BF2896C2B70E7F04371EE6@ganesh.au.lpint.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thanks George.

How do you get an attributes value the following returns the attribute
tag. i.e. rows="100", all i want is the 100.
select
pgxml_xpath(
'<query columns="4"
rows="100"><row><cola>284122</cola><colb>789648</colb><colc>{ts ''2005-02-14
16:13:18''}</colc><cold>unbnda8m5946z55sgi1xco34h1q9tLonoys3nyk1d5tgtLaw8h5w
ya0zdv7vigeiuk9xqLuacdy0dsisopb8g1o4o76090otmq65</cold></row><row><cola>2431
51</cola><colb>750292</colb><colc>{ts ''2005-02-14
16:13:18''}</colc><cold>2d4mat2Lptmdydtgqnc5vnuzxgqxiykqn1c4pr0oduk5gwz25b3L
q05dzqxetee9om45b69ytb48uvziL5xrvyu4k7ng4oouihx0</cold></row><row><cola>7649
29</cola><colb>641215</colb><colc>{ts ''2005-02-14
16:13:18''}</colc><cold>1z5x6dLc9n1vtcLbmk7q6hdriqLa2ub4et41podr7izcro4nkkLs
vp9p0s7obzr27txvknn92m0ps4riqqx7puqoLn2wpmm2z50r</cold></row></query>'
,'//query/@rows','','')

Theo

-----Original Message-----
From: George Weaver [mailto:gweaver(at)shaw(dot)ca]
Sent: Tuesday, 15 February 2005 12:39 AM
To: Theo Galanakis; pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Working with XML.

Hi Theo,

I am not aware of any means of passing xml to stored procedures, apart from
writing your own function to parse the xml.

In regard to your second question - how to access the second record - try
using a more explicit xpath query incorporating a "where" component. For
example, if you wanted to access the second row based upon the value of
cola, you could use '//query/row[(at)cola='525887']/text()'. Or you could
specify the position of the record if you know its position:
'//query/row[2]/text()'.

Microsoft has a very good reference on xpath expressions:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html
/xmrefxpathsyntax.asp
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm
l/xmrefxpathsyntax.asp> .

Regards,
George

----- Original Message -----
From: Theo Galanakis <mailto:Theo(dot)Galanakis(at)lonelyplanet(dot)com(dot)au>
To: pgsql-sql(at)postgresql(dot)org <mailto:pgsql-sql(at)postgresql(dot)org>
Sent: Sunday, February 13, 2005 11:48 PM
Subject: [SQL] Working with XML.

Hi Folks,

Is there a way to pass in an xml string into a stored proc and thenplace
this into a temp table?

I use to be able to do this in sql server, it was quite handy as I could
call one stored proc to update multiple records, here is a sample in sql
server:

select CoverTypeID, ItemSQ, SituationID, ItemDescription, CoverAmount
>From OpenXML ( @XmlHandle, '/cover/covertype/item',1 )
With ( CoverTypeID int '../@id',
ItemSQ int '@id',
SituationID int '@situationID',
ItemDescription varchar(100) '@description',
CoverAmount money '@amount' )

I have managed to get get pgxml_xpath working, however Im not sure how to
access specific rows in an xml document. E.g below there are two records,
how do I access the second record, the following returns both
,'//query/row/cola values being (284122,525887):

select
pgxml_xpath(
'<query columns="4"
rows="100"><row><cola>284122</cola><colb>789648</colb><colc>{ts ''2005-02-14
16:13:18''}</colc><cold>unbnda8m5946z55sgi1xco34h1q9tLonoys3nyk1d5tgtLaw8h5w
ya0zdv7vigeiuk9xqLuacdy0dsisopb8g1o4o76090otmq65</cold></row<row><cola>52588
7</cola><colb>493253</colb><colc>{ts ''2005-02-14
16:13:18''}</colc><cold>6uydk442uz247ga45kpys7htkxznkn8La31qhn942wu2cu2pdr25
mv2nup2zh3vcbh3c4vdauak3p3w093cvtkeyga692b455cr3</cold></row></query>'

,'//query/row/cola/text()','','')

______________________________________________________________________
This email, including attachments, is intended only for the addressee
and may be confidential, privileged and subject to copyright. If you
have received this email in error, please advise the sender and delete
it. If you are not the intended recipient of this email, you must not
use, copy or disclose its content to anyone. You must not copy or
communicate to others content that is confidential or subject to
copyright, unless you have the consent of the content owner.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Konstantin Danilov 2005-02-15 10:16:57 How to view the list of tables ?
Previous Message patrick 2005-02-14 23:26:33 how to select custom value when exists otherwise select default