Wednesday, May 07, 2008

LPX-00601: Invalid token in 'XPath expression'

Always check out the original article at http://www.oraclequirks.com for latest comments, fixes and updates.

You can get this error while attempting to extract nodes containing a namespace prefix using a SQL expression like the following:

select extractValue(
xml_content,
'//openSearch:totalResults') val
from xml_documents
where id = 38;

ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00601: Invalid token in: '//openSearch:totalResults'
The problem is caused by the missing namespace parameter in the function call:

select extractValue(
xml_content,
'//openSearch:totalResults',
'xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"') val
from xml_documents
where id = 38;

VAL
---
175
Clearly the namespace declaration in green, must match the corresponding string in the source XML document.
Note also that Oracle uses double quotes to enclose the string whereas single or double quotes might be used in the source document indifferently, what really matters is the string delimited by the quotes and do not forget that is case sensitive: a mismatching string will cause a null value to be returned instead of the expected node.

See a previous posting on problems related to default namespaces declarations and Oracle XML functions.

2 comments:

Anonymous said...

All,

This is my xml snippet



MCI-130308-UX2M6VNG
a88a792c-1de3-4708-9ecd-5caf4219ad17

I need to extract the value of the tag. Since it has no pre defined name space I am unable to extract it

I tried the below query

select
extract(emp_payload, '//OrderResponse/BuyersID/text()', 'xmlns="urn:uk.org.telcob2b/tML/BT-OrderResponse-v16-0')aa
from emp_messagequeue.

I am getting a null output

Can some one help me?

Byte64 said...

unfortunately the xml snippet doesn't show up because you didn't escape the xml tags, you need to escape angle brackets with their escaped counterpart or replace with square brackets.
Try again.

Flavio

yes you can!

Two great ways to help us out with a minimal effort. Click on the Google Plus +1 button above or...
We appreciate your support!

latest articles