Problem With parsing the XML file.

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
suneyes
Participant
Posts: 82
Joined: Mon Jul 21, 2008 8:42 am

Problem With parsing the XML file.

Post by suneyes »

Hi I Have an XML file in which a row looks something like this,Which is getting interpreted by XML input stage.

<ColumnL>
<Schedule>
<Period>
<Date1>2009.06.24</Date1>
<Date2>2011.06.24</Date2>
</Period>
<Period>
<Date1>2010.06.24</Date1>
<Date2>2012.06.24</Date2>
</Period>
<Period>
<Date1>2011.06.24</Date1>
<Date2>2013.06.24</Date2>
</Period>
<Period>
<Date1>2012.06.25</Date1>
<Date2>2013.06.24</Date2>
</Period>
</Schedule>
</ColumnL>


There are many rows of the type ColumnL.
What my requirement is,to print the Date1 and Date2 text elements of Each Period different ColumnL rows,in a saperate row.So I have taken Period as a repetition element and taken an Xpath expression for the columns as
/ColumnL/Schedule/Date1/text()
/ColumnL/Schedule/Date2/text().

But for each ColumnL in the XML document, the Dates corresponding to first instance of Period is getting repeated.


ie,I am getting the output as

Date1 Date2
2009.06.24 2012.06.24
2009.06.24 2012.06.24
2009.06.24 2012.06.24

where as My required output is

Date1 Date2
2009.06.24 2012.06.24
2011.06.24 2013.06.24
2012.06.25 2013.06.24

I cannot use the indexed Xpath expressions here because I The number of Period elements can vary in each row of ColumnL.

Please suggest me a way to get this problem resolved...[/b]
sun
throbinson
Charter Member
Charter Member
Posts: 299
Joined: Wed Nov 13, 2002 5:38 pm
Location: USA

Post by throbinson »

What is the XPath for the Period repetition key?
suneyes
Participant
Posts: 82
Joined: Mon Jul 21, 2008 8:42 am

Post by suneyes »

throbinson wrote:What is the XPath for the Period repetition key?
ColumnL/Schedule/Period
sun
suneyes
Participant
Posts: 82
Joined: Mon Jul 21, 2008 8:42 am

Post by suneyes »

throbinson wrote:What is the XPath for the Period repetition key?
/ColumnL/Schedule/Period
sun
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

I'm confused here.... to be safe and keeping it clean, especially with the behavior of nulls and repeating elements, one of your date fields ought to be the repeating element, unless you are only going to go as deep as Period in your retrieval (and then play games later with the entire Period element).

/ColumnL/Schedule/Period/Date1/text()
/ColumnL/Schedule/Period/Date2/text()

with either of these as the repetition element. Then you'll get 4 rows from your top example, each with two columns, Date1 and Date2, paired as they are in the xml structure.

From that, please outline what result you "want" to have....

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

I'm confused here.... to be safe and keeping it clean, especially with the behavior of nulls and repeating elements, one of your date fields ought to be the repeating element, unless you are only going to go as deep as Period in your retrieval (and then play games later with the entire Period element).

/ColumnL/Schedule/Period/Date1/text()
/ColumnL/Schedule/Period/Date2/text()

with either of these as the repetition element. Then you'll get 4 rows from your top example, each with two columns, Date1 and Date2, paired as they are in the xml structure.

From that, please outline what result you "want" to have....

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
suneyes
Participant
Posts: 82
Joined: Mon Jul 21, 2008 8:42 am

Post by suneyes »

eostic wrote:I'm confused here.... to be safe and keeping it clean, especially with the behavior of nulls and repeating elements, one of your date fields ought to be the repeating element, unless you are only going to go as deep as Period in your retrieval (and then play games later with the entire Period element).

/ColumnL/Schedule/Period/Date1/text()
/ColumnL/Schedule/Period/Date2/text()

with either of these as the repetition element. Then you'll get 4 rows from your top example, each with two columns, Date1 and Date2, paired as they are in the xml structure.

From that, please outline what result you "want" to have....

Ernie

Thanks Ernie..It helped me in solving my problem
sun
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Glad to hear. Have fun digging deeper into it. The Repetition Element gets especially interesting as you move forward with more complex examples, especially when one of your Date elements (in the example above) happens to not be in the current node......

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
Post Reply