Page 1 of 1

Problem With parsing the XML file.

Posted: Thu Sep 18, 2008 3:42 am
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]

Posted: Thu Sep 18, 2008 5:41 am
by throbinson
What is the XPath for the Period repetition key?

Posted: Thu Sep 18, 2008 8:43 pm
by suneyes
throbinson wrote:What is the XPath for the Period repetition key?
ColumnL/Schedule/Period

Posted: Thu Sep 18, 2008 8:44 pm
by suneyes
throbinson wrote:What is the XPath for the Period repetition key?
/ColumnL/Schedule/Period

Posted: Fri Sep 19, 2008 8:39 am
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

Posted: Fri Sep 19, 2008 8:40 am
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

Posted: Tue Sep 23, 2008 8:00 am
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

Posted: Tue Sep 23, 2008 1:34 pm
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