dbTalk Databases Forums  

xpath and modified standard namespace

comp.databases.postgresql comp.databases.postgresql


Discuss xpath and modified standard namespace in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Volker Boehm
 
Posts: n/a

Default xpath and modified standard namespace - 03-11-2010 , 09:57 AM






Hello,
I'm searching for a solution for the following problem for several hours.
But I can't find any example which corresponds to my Problem.

With this version of an XML-Document everything works fine:

select xpath('//two/text()',
'<top><one>1</one><two>2</two><three>3</three></top>');
result: {2}

This version also works fine:

select xpath('//two/text()',
'<vb:top xmlns:vb="myns"><one>1</one><two>2</two>
<three>3</three></vb:top>');
result: {2}

But this version doesn't work:

select xpath('//two/text()',
'<top xmlns="myns"><one>1</one><two>2</two>
<three>3</three></top>');
result: {}

What is the trick to get xpath() work with a modified standard namespace?

regards Volker

PS: The Linux command line command 'xpath'
echo '<top xmlns="myns"><one>1</one><two>2</two>
<three>3</three></top>' | xpath -e '//two/text()'
makes no difference between the three versions and gives the result '2'.

--
Volker Böhm Tel.: +49 4141 981152 www.vboehm.de
Voßkuhl 5 Fax: +49 4141 981154
D-21682 Stade mailto:volker (AT) vboehm (DOT) de

Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: xpath and modified standard namespace - 03-12-2010 , 04:09 AM






Volker Boehm wrote:
Quote:
I'm searching for a solution for the following problem for several hours.
But I can't find any example which corresponds to my Problem.

With this version of an XML-Document everything works fine:

select xpath('//two/text()',
'<top><one>1</one><two>2</two><three>3</three></top>');
result: {2}

This version also works fine:

select xpath('//two/text()',
'<vb:top xmlns:vb="myns"><one>1</one><two>2</two
three>3</three></vb:top>');
result: {2}

But this version doesn't work:

select xpath('//two/text()',
'<top xmlns="myns"><one>1</one><two>2</two
three>3</three></top>');
result: {}

What is the trick to get xpath() work with a modified standard namespace?
Use the three-argument form of xpath() to declare a namespace
for "myns":

test=> select xpath(
'//def_nsp:two/text()',
'<top xmlns="myns"><one>1</one><two>2</two><three>3</three></top>',
ARRAY[ARRAY['def_nsp', 'myns']]
);

xpath
-------
{2}
(1 row)

Yours,
Laurenz Albe

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.