pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ross Reedstrom <reedstrm@rice.edu>
To: pgsql-sql@postgresql.org
Subject: Re: help with xpath namespace
Date: Tue, 8 Nov 2011 16:59:37 -0600
Message-ID: <20111108225937.GA9891@rice.edu> (raw)
In-Reply-To: <CAExyqyhHwdNoeuexzOya2Ku=pwwoBPDHZZ-qUf7DN9WC85rMGQ@mail.gmail.com>
References: <CAExyqyhP=qYbsrGMKVTwBZrf3sp6xuTOAm6z4cEGB-iJBCDxOg@mail.gmail.com>
	<CAP_rwwk6n0HTyxYd396UWustKom3Ku0dDSs7+u-RNr7kqX+6TA@mail.gmail.com>
	<CAExyqyhHwdNoeuexzOya2Ku=pwwoBPDHZZ-qUf7DN9WC85rMGQ@mail.gmail.com>

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
> 



view thread (4+ messages)

Message-ID: <20111108225937.GA9891@rice.edu>
Permalink:  ../20111108225937.GA9891@rice.edu/
Also on:    postgresql.org/message-id/20111108225937.GA9891@rice.edu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: reedstrm@rice.edu
  Subject: Re: help with xpath namespace
  In-Reply-To: <20111108225937.GA9891@rice.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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