This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having issue extracting text from xmltype

 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic