Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpFGi-005nzW-Rf for pgsql-sql@arkaria.postgresql.org; Tue, 26 Mar 2024 22:27:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rpFGh-00706y-Ta for pgsql-sql@arkaria.postgresql.org; Tue, 26 Mar 2024 22:27:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpFGh-00704V-KH for pgsql-sql@lists.postgresql.org; Tue, 26 Mar 2024 22:27:43 +0000 Received: from mail-ed1-f54.google.com ([209.85.208.54]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rpFGd-006bFd-Ru for pgsql-sql@lists.postgresql.org; Tue, 26 Mar 2024 22:27:42 +0000 Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-56c147205b9so526309a12.0 for ; Tue, 26 Mar 2024 15:27:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711492059; x=1712096859; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=urivtlzZUmKEdPgk1nImey5ei7vJ/wDbjNA3bZ+Nff8=; b=lKSFmvige2ZtOF022KQoXmw87im1Vw0qvmjVSlWDGmGTosTKexF2yW5GJBEVbRoy9k yx/V/2dFssZoEmamNVewdNgMrvr9fmpeZ8L/7copILV8z8rN8/SBh3JRWGNTufep+UkN mDQkdEhfWiDbSgTrvZ/eJ8yEDnTiUJgZYnzh7LcI77Ka70lCVp8LLnmufEmJDyAtu8lN fQweqPAyG/rZmcFQdO5LFkB9XF7zRh9P6CcBDVrkC9Zx25hrA/nOSodLIgt9cy2QDIwh QZHAX4/exdCX2FKN45sDBzpyd1CzBhQSv/5D3K4kLF0+JLNcg2PmC1nEzWmwvSyi/2ei /b0g== X-Gm-Message-State: AOJu0YwNvyw6e9kBVL37qvcSaGkJenDm10oGxxz9bnQ1npoz3kWpMQJS RawjUbADe7n7I1+al+K2epNkL9A2RRIfGKg5YhI57IF6rmAAyiYL+TgqLo+Lazisbw== X-Google-Smtp-Source: AGHT+IH/KoJKSJvG27j3aYXcWaCZQl/nYiunYZyVEOn8pA6MQrPyBxyhYd/IWKoNONCOBhQFEV/iVg== X-Received: by 2002:a50:8e51:0:b0:568:d6a2:716 with SMTP id 17-20020a508e51000000b00568d6a20716mr2783315edx.7.1711492059101; Tue, 26 Mar 2024 15:27:39 -0700 (PDT) Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com. [209.85.221.49]) by smtp.gmail.com with ESMTPSA id ds2-20020a0564021cc200b00568d750f7b2sm4561509edb.65.2024.03.26.15.27.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Mar 2024 15:27:38 -0700 (PDT) Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-33ed4dd8659so175718f8f.0 for ; Tue, 26 Mar 2024 15:27:38 -0700 (PDT) X-Received: by 2002:a5d:4243:0:b0:33e:5970:e045 with SMTP id s3-20020a5d4243000000b0033e5970e045mr2517745wrr.21.1711492058786; Tue, 26 Mar 2024 15:27:38 -0700 (PDT) MIME-Version: 1.0 References: <2c00e954c31459c43f0d78119c1bd0547f7eddb2.camel@ft-c.de> In-Reply-To: <2c00e954c31459c43f0d78119c1bd0547f7eddb2.camel@ft-c.de> From: Steve Midgley Date: Tue, 26 Mar 2024 15:27:27 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: xml build a list of all elements To: ml@ft-c.de Cc: pgsql-sql@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000333c7c061497cc78" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000333c7c061497cc78 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 26, 2024 at 2:05=E2=80=AFPM ft wrote: > Hello, > > I have a postgresql database table with xml data. > What I need is a list of all elements and attributes. > Example: > > > comment > comment > > > > 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 --000000000000333c7c061497cc78 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, Mar 26, 2024= at 2:05=E2=80=AFPM ft <ml@ft-c.de>= wrote:
Hello,= =C2=A0

I have a postgresql database table with xml data.=C2=A0
What I need is a list of all elements and attributes.
Example:
<area>
=C2=A0 <sub>
=C2=A0 =C2=A0<sub2 attr=3D'1'>comment</sub2>
=C2=A0 =C2=A0<sub2 attr=3D'2'>comment</sub2>
=C2=A0 <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 lang= uage 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 t= he server, but I have no idea about security/resource consumption implicati= ons of that approach. But if you can get Python's lxml installed on you= r Pg server, having a library like that would (for me) make this function a= lot easier to write..

Steve
--000000000000333c7c061497cc78--