View previous topic :: View next topic
|
Author |
Message |
mallik4u
New User
Joined: 17 Sep 2008 Posts: 75 Location: bangalore
|
|
|
|
hi,
I am trying to PARSE the XML similar to the following. I am able to PARSE it when i have only 1 <container> tag under <Containers>. But when it is more than 1, I am getting SQLCODE -16003. Any help will be greatly appreciated.
<Main>
<Containers>
<container>1</container>
<container>1</container>
</Containers>
<Items>
<Item name="abc"> I1 </Item>
<Item name="abc"> I2 </Item>
<Item name="abc"> I3 </Item>
</Items>
</Main>
SQL I am using:
SELECT X.*
FROM XMLTABLE ('$XMLINPUT/Main/Items/Item'
PASSING XMLPARSE(DOCUMENT
(TRIM('<Main>
<Containers>
<container>1</container>
<container>1</container>
</Containers>
<Items>
<Item name="abc"> I1 </Item>
<Item name="abc"> I2 </Item>
<Item name="abc"> I3 </Item>
</Items>
</Main>'))) as XMLINPUT
COLUMNS
item char(10) PATH '.',
ctr char(10) PATH '../../Containers/container'
) AS X
Thanks,
Mallik |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
Back to top |
|
|
mallik4u
New User
Joined: 17 Sep 2008 Posts: 75 Location: bangalore
|
|
|
|
Thank you GuyC.
My requirement is to get all the details of <container> and <Item>. Both of them can be repeated.
Could you please let me know how we can both the tags? |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
there is no relationship between container and item, so that would be 2 tables/2 selects
Code: |
with myxml(doc) as (
select XMLPARSE(DOCUMENT
(TRIM('<Main>
<Containers>
<container>1</container>
<container>2</container>
</Containers>
<Items>
<Item name="abc"> I1 </Item>
<Item name="abc"> I2 </Item>
<Item name="abc"> I3 </Item>
</Items>
</Main>'))) as myxmldoc
from sysibm.sysdummy1
)
SELECT 'Item', X.*
FROM myxml
, XMLTABLE ('$XMLINPUT/Main/Items/Item'
PASSING doc as XMLINPUT
COLUMNS item char(10) PATH '.'
) AS X
union all
SELECT 'ctr', y.*
FROM myxml
, XMLTABLE ('$XMLINPUT/Main/Containers/container'
PASSING doc as XMLINPUT
COLUMNS ctr char(10) PATH '.'
) AS y |
|
|
Back to top |
|
|
mallik4u
New User
Joined: 17 Sep 2008 Posts: 75 Location: bangalore
|
|
|
|
Thanks Guyc.
It helps. |
|
Back to top |
|
|
|