Help with namespaces in xpath (PostgreSQL 9.5.3) - Mailing list pgsql-general

From Allan Kamau
Subject Help with namespaces in xpath (PostgreSQL 9.5.3)
Date
Msg-id CAF3N6oS+EB78LNS0eEpX29WSHiG_nCv77uHPuKtRNqDwruMNMA@mail.gmail.com
Whole thread Raw
Responses Re: Help with namespaces in xpath (PostgreSQL 9.5.3)  ("David G. Johnston" <david.g.johnston@gmail.com>)
List 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.

pgsql-general by date:

Previous
From: Tim Smith
Date:
Subject: Help needed structuring Postgresql correlation query
Next
From: Johan Thomsen
Date:
Subject: pg_dump from a hot standby replication slave