From: | Allan Kamau <kamauallan(at)gmail(dot)com> |
---|---|
To: | Postgres General Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Help with namespaces in xpath (PostgreSQL 9.5.3) |
Date: | 2016-06-19 21:09:08 |
Message-ID: | CAF3N6oS+EB78LNS0eEpX29WSHiG_nCv77uHPuKtRNqDwruMNMA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I have an xml document from which I would like to extract the contents of
several elements.
I would like to use xpath to extract the contents of "name" from the xml
document shown below.
WITH x AS
(
SELECT
'<?xml version="1.0" encoding="UTF-8"?>
<uniprot xmlns="http://uniprot.org/uniprot" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://uniprot.org/uniprot http://www.uniprot.org/support/docs/uniprot.xsd">
<entry dataset="Swiss-Prot" created="2009-12-15" modified="2016-05-11"
version="56">
<accession>A0JM59</accession>
<name>UBP20_XENTR</name>
</entry>
</uniprot>
'::xml AS d
)
SELECT (xpath('/uniprot/entry/name/text()',a.d))[1]::text AS uniprot_name
FROM
x AS a
;
The documentation for xpath() ("
https://www.postgresql.org/docs/9.5/static/functions-xml.html") describes
"xpath(xpath, xml [, nsarray]").
For the above xml document, what would be the two dimensional array
"nsarray" for the xpath() function?
-Allan.
From | Date | Subject | |
---|---|---|---|
Next Message | Tatsuro Yamada | 2016-06-20 01:40:36 | Re: Pg_bulkload for PostgreSql 9.5 |
Previous Message | Tim Smith | 2016-06-19 08:58:58 | Help needed structuring Postgresql correlation query |