If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Extract XML Data.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-07-11, 17:31
Rajesh1203 Rajesh1203 is offline
Registered User
 
Join Date: Aug 2010
Posts: 38
Extract XML Data.

Hello All,
I am struggling to extract data from an XML records using the XQuery,Can someone give me the query on how to extract the data given below from the XML below:

XML

<ns2:EntityDetails xmlns:ns2="http://www.ssme.com/slmFlex">
<ns2:Entity Type="com.fourcs.clm.iwarranty.wc.domain.VehicletR egistration" Id="7018">
<ns2:Field Type="java.lang.String" Name="VEHICLEAPPLICATION">11</ns2:Field>
<ns2:Field Type="java.lang.String" Name="VEHICLEMANUFACTURER">110</ns2:Field>
<ns2:Field Type="java.lang.String" Name="VEHICLEMODEL"/>
</ns2:Entity>
</ns2:EntityDetails>


My output should be ::
11

Column name in which the above XML is stored is XML_DATA and the Table name is VEHICLE_REGN

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 06-07-11, 17:44
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
What have you tried so far?
Reply With Quote
  #3 (permalink)  
Old 06-07-11, 18:08
Rajesh1203 Rajesh1203 is offline
Registered User
 
Join Date: Aug 2010
Posts: 38
I tried the following queries:

SELECT XMLQUERY('declare default elemnt namespace "http://www.ssme.com/slmFlex";
$c/ns2:EntityDetails' passing XML_DATA as "c" )

from PROWNER.VEHICLE_REGN;

select t.VEHICLEMODEL, i.REF_CD, t.VEHICLEMANUFACTURER, T.VEHICLEAPPLICATION from PROWNER.VEHICLE_FLEX i,
xmltable('$XML_DATA/*:EntityDetails/*:Entity'
columns VEHICLEMANUFACTURER varchar(100) path 'VEHICLEMANUFACTURER',
VEHICLEAPPLICATION varchar(100) path 'VEHICLEAPPLICATION',
VEHICLEMODEL varchar(100) path 'VEHICLEMODEL') as t
Reply With Quote
  #4 (permalink)  
Old 06-07-11, 21:07
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I'm not sure what is the source of your XQuery syntax exercises, but neither of them looks right.

May be this will give you some ideas: XQuery reference - IBM DB2 9.7 for Linux, UNIX, and Windows
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On