Benita Blas

Benita Blas

  • NA
  • 1
  • 0

Finding data between a period-Linq to XML

Sep 21 2010 5:52 AM
 
var xelement = XElement.Parse(@"
	<root>
	<contet id=""01"">
 <period>
	<startDate>2007-01-01</startDate>
	<endDate>2007-12-31</endDate>
 </period>
</contet>
<contet id=""04"">
 <segment>
	<eplicit Value=""Sample"">Member</eplicit>
 </segment>
 <period>
	<startDate>2007-01-01</startDate>
	<endDate>2007-12-31</endDate>
 </period>
</contet>
<contet id=""13"">
 <period>
	<startDate>2006-01-01</startDate>
	<endDate>2006-12-31</endDate>
 </period>
</contet>
<SampleTag contetRef=""04"" >01234</SampleTag>
<SampleTag contetRef=""13"" >04556</SampleTag>
<SampleTag contetRef=""22"" >427000000</SampleTag>
<SampleTag contetRef=""19"" >427000000</SampleTag>
<SampleTag contetRef=""10"" >23450</SampleTag>
<SampleTag contetRef=""01"" >45890</SampleTag>
</root>");

var contextIds = from st in xelement.Elements("SampleTag")
				 join ct in
			( xelement
	.Elements("contet")
	.Elements("period")
	.Where (e => DateTime.Parse(e.Element("startDate").Value) >= new DateTime(2006,12,01) && 
	DateTime.Parse(e.Element("endDate").Value) <= new DateTime(2008,12,31))
	.Select (e => e.Parent.Attribute("id").Value)) on st.Attribute("contetRef").Value equals ct
	select st.Value;


 

Hi,
My input are:
Element: Sample Tag
Period:   2006-12-01 to 2008-12-31
I want to query first for getting all the SampleTag, then i have to read the contextRef value avaialble in that SampleTag.
 I need to filter the SampleTag using the period whose contextRef and content ID matches.
Finally I need to get the attibute value of the filtered SampleaTag. I have queried as shown in code block.
But I am getting an error "object reference not set to instance of an object" as contextIds value.
Please help me..