Linq to xml, how to retrieve data

Asked By kris kumar
26-Jan-10 07:27 PM
Earn up to 0 extra points for answering this tough question.

Hello All,

I am new to Linq and trying to findout how I can retrive some data from the following sample xml. Could you please help? thanks for the help.

I need to find the valid items name and descr for a particular Display name. For example,  if I pass "Sample Item", the query should return the elements xxy and xxx. ie. from the Header section, findout the validItems for "Sample Item". this should be, xxx and xxy. then, fromt he data section, get the xxx and xxy.



 <Response>
  <Data>
           <Item id="xxx">
        <Name>ABC</Name>
        <Desc>This is a sample</Desc>
        </Item>

     <Item id="xxy">
        <Name>ABCd</Name>
        <Desc>This is a sample</Desc>
    </Item>
     <Item id="xxz">
        <Name>ABCde</Name>
        <Desc>This is a sample</Desc>
    </Item>

  </Data>
  <Header>
    <Display Name="Sample Item">
    <ValidItems>xxx,xxy </ValidItems>
    </Display>

    <Display Name="Sample Item2">
    <ValidItems>xxz </ValidItems>
    </Display>
  </Header>
  </Response>

  Linq to xml, how to retrieve data

Create New Account