From: | Brian Sherwood <bdsher(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | help with xpath namespace |
Date: | 2011-09-22 15:03:53 |
Message-ID: | CAExyqyhP=qYbsrGMKVTwBZrf3sp6xuTOAm6z4cEGB-iJBCDxOg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
I am trying to use xpath to extract some information from a XML document.
(if it matters, It's the router config for a Juniper router)
I believe I am having problems with the namespace.
I am trying to extract the serial-number, but I am not getting anything.
Here is the script I have been testing with:
BEGIN;
CREATE TABLE "xml_test" (
data_xml xml
);
INSERT INTO xml_test (data_xml) VALUES ('
<chassis-inventory xmlns="http://xml.juniper.net/junos/9.6R4/junos-chassis">
<chassis junos:style="inventory">
<name>Chassis</name>
<serial-number>JN1111111111</serial-number>
<description>MX960</description>
</chassis>
</chassis-inventory>');
select data_xml from xml_test where data_xml is document;
select (xpath('/chassis-inventory/chassis/serial-number/text()',
data_xml,
ARRAY[ARRAY['junos',
'http://xml.juniper.net/junos/9.6R4/junos-chassis']]
)) from xml_test;
ROLLBACK;
This gives me the following:
BEGIN
CREATE TABLE
INSERT 0 1
data_xml
-------------------------------------------------------------------------------
<chassis-inventory xmlns="http://xml.juniper.net/junos/9.6R4/junos-chassis">+
<chassis junos:style="inventory"> +
<name>Chassis</name> +
<serial-number>JN1111111111</serial-number> +
<description>MX960</description> +
</chassis> +
</chassis-inventory>
(1 row)
xpath
-------
{}
(1 row)
ROLLBACK
Can anyone suggest how I would go about getting the serial-number with xpath?
Thanks
From | Date | Subject | |
---|---|---|---|
Next Message | John Fabiani | 2011-09-23 02:49:20 | using the aggregate function max() |
Previous Message | Amar Dhole | 2011-09-22 06:11:39 | Re: handling duplicate row exception |