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 > xml problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-27-11, 12:58
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
xml problem

hi, can i ask a hand on this...

how can i query in the xml document,
customers having state="Australia"
with the gender="female"

using the function xmlexists

<Customer>
<name>shane</name>
<address>
<state>Australia</state>
<zipcode>0012</zipcode>
</address>
<gender>female</gender>
</Customer>


here is my code.
Quote:
select id from
customer
where xmlexist($cust_xml/customer/address[state="Australia"]')
Reply With Quote
  #2 (permalink)  
Old 09-27-11, 13:42
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Thusly?
Code:
$cust_xml/customer[address/state="Australia" and gender="female"]
Reply With Quote
  #3 (permalink)  
Old 09-27-11, 14:07
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
Quote:
Originally Posted by n_i View Post
Thusly?
Code:
$cust_xml/customer[address/state="Australia" and gender="female"]

Hi, i tried your code but there is no display...but when i look at in my table there is one record that having state="Australia" gender="female'


Thank you in advance.
Reply With Quote
  #4 (permalink)  
Old 09-27-11, 14:58
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
You know that XML is case-sensitive, don't you?
Reply With Quote
  #5 (permalink)  
Old 09-27-11, 21:55
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
Quote:
Originally Posted by n_i View Post
You know that XML is case-sensitive, don't you?

hi, yes i know it's case sensitive...i made another query that will only filter having state="Australia" and there are records display.



Kindly Regrads,

Jemz
Reply With Quote
  #6 (permalink)  
Old 09-27-11, 22:30
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Code:
>db2 -tvf c:\temp\t.sql
with x(c) as (values xmlparse(document 
'<Customer> 
 <name>shane</name> 
 <address> 
  <state>Australia</state> 
  <zipcode>0012</zipcode> 
 </address> 
 <gender>female</gender> 
</Customer>'
)) select x.* from sysibm.sysdummy1 d, x 
where xmlexists (
'$i/Customer[address/state="Australia" and gender="female"]'
passing x.c as "i")

C

---------------------------------------------------------------------------------------
<Customer><name>shane</name><address><state>Australia</state><zipcode>0012</zipcode></address><gender>female</gender></C
ustomer>




  1 record(s) selected.
Reply With Quote
  #7 (permalink)  
Old 09-27-11, 23:32
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
[QUOTE=n_i;6519962]
Code:
>db2 -tvf c:\temp\t.sql
with x(c) as (values xmlparse(document 
'<Customer> 
 <name>shane</name> 
 <address> 
  <state>Australia</state> 
  <zipcode>0012</zipcode> 
 </address> 
 <gender>female</gender> 
</Customer>'
)) select x.* from sysibm.sysdummy1 d, x 
where xmlexists (
'$i/Customer[address/state="Australia" and gender="female"]'
passing x.c as "i")

C

---------------------------------------------------------------------------------------
<Customer><name>shane</name><address><state>Australia</state><zipcode>0012</zipcode></address><gender>female</gender></C
ustomer>




  1 record(s) selected.
[/QUOTE



wow nice are you doing this in db2ce?is this the way to insert the xml in db2ce...i use datastudio to insert using stored procedure...

by the way thank you for this and i will come back if this will work.more power to you


Best Regards,

Jemz
Reply With Quote
  #8 (permalink)  
Old 09-28-11, 05:39
jemz jemz is offline
Registered User
 
Join Date: Aug 2011
Posts: 76
Quote:
Originally Posted by n_i View Post
Thusly?
Code:
$cust_xml/customer[address/state="Australia" and gender="female"]

Hi,

it's working now...thank you for solving my problem..by the way where i can get this some tutorial or reference in filtering like my problem or other problem related to xml...thank you so much.
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