I have an XDocument object from which I am trying to extract all the List which specify a specific criteria.
Following is my XML
<MyQueue xmlns:ns0 = "http://myprogram">
<ns0:QueueReport>
<ns0:number>001</ns0:number>
<ns0:id>A</ns0:id>
<ns0:name>ABC</ns0:name>
<ns0:hours>1</ns0:hours>
</ns0:QueueReport>
<ns0:QueueReport>
<ns0:number>001</ns0:number>
<ns0:id>B</ns0:id>
<ns0:name>ABC</ns0:name>
<ns0:hours>2</ns0:hours>
</ns0:QueueReport>
<ns0:QueueReport>
<ns0:number>001</ns0:number>
<ns0:id>B</ns0:id>
<ns0:name>ABC</ns0:name>
<ns0:hours>10</ns0:hours>
</ns0:QueueReport>
<ns0:QueueReport>
<ns0:number>002</ns0:number>
<ns0:id>A</ns0:id>
<ns0:name>ABC</ns0:name>
<ns0:hours>12</ns0:hours>
</ns0:QueueReport>
<ns0:QueueReport>
<ns0:number>003</ns0:number>
<ns0:id>A</ns0:id>
<ns0:name>ABC</ns0:name>
<ns0:hours>20</ns0:hours>
</ns0:QueueReport>
</ns0:MyQueue>
The above XML is in an XDocument object say xdoc. I write the following to exract the nodes and its children.
XNamespace b = @"http://myprogram";
var elements = from e xdoc.Elements(b + "MyQueue")
where e.Element(b + "QueueReport").Element(b + "number").Value == "001"
&& e.Element(b + "QueueReport").Element(b + "id").Value == "B"
select e.Elements(b + "QueueReport").ToList();
(Please excuse the typos if any in the code, it was not written in the editor)
The elements variable does not have any results, ideally i would have expected the below two elements in the List.
<ns0:QueueReport>
<ns0:number>001</ns0:number>
<ns0:id>B</ns0:id>
<ns0:name>ABC</ns0:name>
<ns0:hours>2</ns0:hours>
</ns0:QueueReport>
<ns0:QueueReport>
<ns0:number>001</ns0:number>
<ns0:id>B</ns0:id>
<ns0:name>ABC</ns0:name>
<ns0:hours>10</ns0:hours>
</ns0:QueueReport>
Please help, I am very new to Linq and have little clue about how else can I achieve this.