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.
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.