public inbox for [email protected]  
help / color / mirror / Atom feed
xml build a list of all elements
2+ messages / 2 participants
[nested] [flat]

* xml build a list of all elements
@ 2024-03-26 21:04 ft <[email protected]>
  2024-03-26 22:27 ` Re: xml build a list of all elements Steve Midgley <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: ft @ 2024-03-26 21:04 UTC (permalink / raw)
  To: [email protected]

Hello, 

I have a postgresql database table with xml data. 
What I need is a list of all elements and attributes.
Example:
<area>
  <sub>
   <sub2 attr='1'>comment</sub2>
   <sub2 attr='2'>comment</sub2>
  <sub>
</area>

The result should be:
/area
/area/sub
/area/sub/sub2
/area/sub/sub2@attr
/area/sub/sub2
/area/sub/sub2@attr

or distinct (it's enough)
/area
/area/sub
/area/sub/sub2
/area/sub/sub2@attr

Is there a postgresql function to build this list?

Franz





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: xml build a list of all elements
  2024-03-26 21:04 xml build a list of all elements ft <[email protected]>
@ 2024-03-26 22:27 ` Steve Midgley <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Steve Midgley @ 2024-03-26 22:27 UTC (permalink / raw)
  To: [email protected]; +Cc: [email protected]

On Tue, Mar 26, 2024 at 2:05 PM ft <[email protected]> wrote:

> Hello,
>
> I have a postgresql database table with xml data.
> What I need is a list of all elements and attributes.
> Example:
> <area>
>   <sub>
>    <sub2 attr='1'>comment</sub2>
>    <sub2 attr='2'>comment</sub2>
>   <sub>
> </area>
>
> The result should be:
> /area
> /area/sub
> /area/sub/sub2
> /area/sub/sub2@attr
> /area/sub/sub2
> /area/sub/sub2@attr
>
> or distinct (it's enough)
> /area
> /area/sub
> /area/sub/sub2
> /area/sub/sub2@attr
>
> Is there a postgresql function to build this list?
>
>
> I think it can be done but it'll be a painful function. I'd personally
recommend writing this in a higher level language that deals with xml as
rationally as it is possible to deal with xml (which is very unfriendly to
most programming languages). Possibly you could consider using a PL/Python
extension if you want processing to happen on the server, but I have no
idea about security/resource consumption implications of that approach. But
if you can get Python's lxml installed on your Pg server, having a library
like that would (for me) make this function a lot easier to write..

Steve


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-03-26 22:27 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-03-26 21:04 xml build a list of all elements ft <[email protected]>
2024-03-26 22:27 ` Steve Midgley <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox