aspose file tools*
The moose likes JDBC and the fly likes Having issue extracting text from xmltype Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Having issue extracting text from xmltype" Watch "Having issue extracting text from xmltype" New topic
Author

Having issue extracting text from xmltype

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I am not sure what is going on here.
Here is the xml (it is all on one line or I would format it for readability - but this is what I am working with):

<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://url"><S:Body><ns2:getaction xmlns:ns2="http://url"><return>http://urltext</return></ns2:getaction></S:Body></S:Envelope>

I can extract using the following:


which returns
<return>http://urltext</return>
as you might expect

However, if I try to get just the text, and not the <return>'s by adding /text()


I get
Error at line 1
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00210: expected '<' instead of 'h'
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 272
ORA-06512: at line 17

Script Terminated on line 1.

I am stumped (again... today has been annoying..)

Could it have to do with the fact the xml is one line? Or is it possible the value in <return> is not /text()?


I have tried going further up in the xml tree, and adding namespaces, all of which I have done successfully before - I cannot figure out what is happening here though


True wisdom is in knowing you know nothing - Socrates
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

I'm just guessing there, but I'd say the problem is that the extract method correctly extracts the value (http://urltext), but it is not a valid XML and cannot therefore be passed to functions (in this case the XMLTYPE constructor) that expect XML snippets as input? That is, shouldn't you do:
where result would be declared as a clob?
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

You are correct, that was the problem. I was looking at some old work I had done like this, and made an incorrect assumption about the results I was storing (I thought I was storing the data in an XMLTYPE variable with just the string and no XML - turns out there is XML which I later parse out - your suggestion would be better for that older work too.
Thanks Martin, very helpful as usual
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

You're welcome.
 
 
subject: Having issue extracting text from xmltype