pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedhelp with xpath namespace
4+ messages / 3 participants
[nested] [flat]
* help with xpath namespace
@ 2011-09-22 15:03 Brian Sherwood <bdsher@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Brian Sherwood @ 2011-09-22 15:03 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: help with xpath namespace
@ 2011-09-23 16:14 Filip Rembiałkowski <plk.zuber@gmail.com>
parent: Brian Sherwood <bdsher@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Filip Rembiałkowski @ 2011-09-23 16:14 UTC (permalink / raw)
To: Brian Sherwood <bdsher@gmail.com>; +Cc: pgsql-sql
2011/9/22 Brian Sherwood <bdsher@gmail.com>
>
> 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;
>
> Can anyone suggest how I would go about getting the serial-number with
> xpath?
>
>
http://www.postgresql.org/docs/9.1/static/functions-xml.html#FUNCTIONS-XML-PROCESSING-
see "mydefns".
This will work:
select xpath(
'/junos:chassis-inventory/junos:chassis/junos:serial-number/text()',
data_xml,
ARRAY[ARRAY['junos', 'http://xml.juniper.net/junos/9.6R4/junos-chassis';
]]
)
from xml_test;
cheers, Filip
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: help with xpath namespace
@ 2011-09-26 13:56 Brian Sherwood <bdsher@gmail.com>
parent: Filip Rembiałkowski <plk.zuber@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Brian Sherwood @ 2011-09-26 13:56 UTC (permalink / raw)
To: Filip Rembiałkowski <plk.zuber@gmail.com>; +Cc: pgsql-sql
Yep, that did it.
Thanks!
2011/9/23 Filip Rembiałkowski <plk.zuber@gmail.com>:
>
>
> 2011/9/22 Brian Sherwood <bdsher@gmail.com>
>>
>> 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;
>>
>> Can anyone suggest how I would go about getting the serial-number with
>> xpath?
>>
>
>
> http://www.postgresql.org/docs/9.1/static/functions-xml.html#FUNCTIONS-XML-PROCESSING
> - see "mydefns".
>
> This will work:
>
> select xpath(
> '/junos:chassis-inventory/junos:chassis/junos:serial-number/text()',
> data_xml,
> ARRAY[ARRAY['junos',
> 'http://xml.juniper.net/junos/9.6R4/junos-chassis';]]
> )
> from xml_test;
>
>
>
> cheers, Filip
>
>
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: help with xpath namespace
@ 2011-11-08 22:59 Ross Reedstrom <reedstrm@rice.edu>
parent: Brian Sherwood <bdsher@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Ross Reedstrom @ 2011-11-08 22:59 UTC (permalink / raw)
To: pgsql-sql
On Mon, Sep 26, 2011 at 09:56:06AM -0400, Brian Sherwood wrote:
> Yep, that did it.
>
> Thanks!
ProTip (for the list archive): since the namespace alias in the query and the
original XML don't need to match (in this common case, the document uses a
default namespace, which isn't available in xpaths), you can save significant
typing by using a single-character namespace:
select xpath(
'/j:chassis-inventory/j:chassis/j:serial-number/text()',
data_xml,
ARRAY[ARRAY['j',
'http://xml.juniper.net/junos/9.6R4/junos-chassis';]]
)
from xml_test;
Ross
>
>
> 2011/9/23 Filip Rembiałkowski <plk.zuber@gmail.com>:
> >
> >
> > 2011/9/22 Brian Sherwood <bdsher@gmail.com>
> >>
> >> 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;
> >>
> >> Can anyone suggest how I would go about getting the serial-number with
> >> xpath?
> >>
> >
> >
> > http://www.postgresql.org/docs/9.1/static/functions-xml.html#FUNCTIONS-XML-PROCESSING
> > - see "mydefns".
> >
> > This will work:
> >
> > select xpath(
> > '/junos:chassis-inventory/junos:chassis/junos:serial-number/text()',
> > data_xml,
> > ARRAY[ARRAY['junos',
> > 'http://xml.juniper.net/junos/9.6R4/junos-chassis';]]
> > )
> > from xml_test;
> >
> >
> >
> > cheers, Filip
> >
> >
> >
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2011-11-08 22:59 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-09-22 15:03 help with xpath namespace Brian Sherwood <bdsher@gmail.com>
2011-09-23 16:14 ` Filip Rembiałkowski <plk.zuber@gmail.com>
2011-09-26 13:56 ` Brian Sherwood <bdsher@gmail.com>
2011-11-08 22:59 ` Ross Reedstrom <reedstrm@rice.edu>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox