IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

XML PARSING


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
mallik4u

New User


Joined: 17 Sep 2008
Posts: 75
Location: bangalore

PostPosted: Thu Feb 26, 2015 9:27 pm
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Feb 27, 2015 5:33 pm
Reply with quote

www.ibm.com/developerworks/data/library/techarticle/dm-0708nicola/#Handling_multiple_values_per_cell

which container do you want for each Item ?
first : use PATH '../../Containers/container[1]'
all : use PATH 'fn:string-join(../../Containers/container/text(),",")'
Back to top
View user's profile Send private message
mallik4u

New User


Joined: 17 Sep 2008
Posts: 75
Location: bangalore

PostPosted: Thu Mar 26, 2015 4:33 pm
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Apr 01, 2015 2:12 pm
Reply with quote

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
View user's profile Send private message
mallik4u

New User


Joined: 17 Sep 2008
Posts: 75
Location: bangalore

PostPosted: Wed Apr 01, 2015 2:16 pm
Reply with quote

Thanks Guyc.
It helps.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Parsing Large JSON file using COBOL COBOL Programming 4
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
No new posts parsing with startat and endbefr SYNCSORT 10
No new posts XML Parsing in COBOL creating "h... COBOL Programming 0
This topic is locked: you cannot edit posts or make replies. Parsing more than 1000 columns in a s... SYNCSORT 10
Search our Forums:

Back to Top