XML Parsing With Repeating Elements

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
bikramg
Participant
Posts: 28
Joined: Thu Apr 12, 2012 3:54 pm
Location: NZ

XML Parsing With Repeating Elements

Post by bikramg »

Hi All,

Trying to read a XML files and capture the output in a table. Got the basic part working as but getting the repeating elements working has become a challenge, hence shouting for help (have seen other threads along the same lines but not quite the same). Anyway, here is the format of the XML repeating element that I want to read -

Code: Select all

  <actionResultStatus action="SomeAction">
      <status>Success</status>
   </actionResultStatus>
   <actionResultStatus action="ActionAgain">
      <status>Failure</status>
      <message>
         <code>SomeCode_1</code>
         <context>SomeContext_1</context>
         <message>SomeMessage_1</message>
         <severity>ERROR</severity>
         <action>failed</action>
         <oid>oid</oid>
  <pathToFailedComponent>/Root/SomePath_1</pathToFailedComponent>
      </message>
      <message>
         <code>SomeCode_2</code>
         <context>SomeContext_2</context>
         <message>SomeMessage_2</message>
         <severity>ERROR</severity>
         <action>failed</action>
         <oid>oid</oid>
         <pathToFailedComponent>/Root/SomePath_2</pathToFailedComponent>
      </message>
   </actionResultStatus>

In my definition \ XML Metadata I have text of "status", "code" & "message" (at the second level).

What is happening is I'm getting the first of the status which in this case is "Success" and code and & message for the first instance of the Failure section. I need to be able to capture all of the repeating elements (preferably would like to skip the success one - only need to Failures to be honest).

Thanks,
Bikram
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

ps. You can't use BBCode (like code tags) in your post and expect it to work when you turn on the 'Disable BBCode in this post' option.

Fixed.
-craig

"You can never have too many knives" -- Logan Nine Fingers
bikramg
Participant
Posts: 28
Joined: Thu Apr 12, 2012 3:54 pm
Location: NZ

Post by bikramg »

Craig, sorry for overlooking that bit.

Any ideas about the actual problem, anyone!
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

...are you using the xmlInput Stage?

Assuming you have worked out how to "feed" the stage, start with two columns, with xpath in the Description property that looks like this:

status varchar 20 /actionResultStatus/status/text()
severity varchar 20 /actionResultStatus/message/severity/text()

Make severity a key.

Be sure that you do NOT check "repetition element required". You should get 3 rows.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
bikramg
Participant
Posts: 28
Joined: Thu Apr 12, 2012 3:54 pm
Location: NZ

Post by bikramg »

OK. Found the problem I was marking the wrong item as "Key". I changed my key to code which really is my repeating element that I want, it worked like magic.
Post Reply