Re: xml build a list of all elements

Поиск
Список
Период
Сортировка
От Steve Midgley
Тема Re: xml build a list of all elements
Дата
Msg-id CAJexoSLc5kimE1C83xjA9p_MLcvNyLs3Y1XjBe1M6mSpkBaoaQ@mail.gmail.com
обсуждение исходный текст
Ответ на xml build a list of all elements  (ft <ml@ft-c.de>)
Список pgsql-sql


On Tue, Mar 26, 2024 at 2:05 PM ft <ml@ft-c.de> 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

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

Предыдущее
От: ft
Дата:
Сообщение: xml build a list of all elements
Следующее
От: James Cloos
Дата:
Сообщение: [MASSMAIL]help with a particular multi-table query