0

I am working on one silverlight application. I need one help regarding LInq to xml.

It is basically ERP system where objects are dynamic and entity creation is dynamic. I have added SilverlightTable concept with dynamic objects in the applicaiton.

I have one xml like :

<NewDataSet>
  <Table>
    <knd_entity_Id>1</knd_entity_Id>
    <CheckboxCol>0</CheckboxCol>
    <kndtbkndnr>4001</kndtbkndnr>
    <kndtbkndstatus>1</kndtbkndstatus>
    <kndtbkndname1>Fritz &amp; Franz Bikes GmbH</kndtbkndname1>
    <kndtbkndname3 />
    <kndtbkndplzstr>59321</kndtbkndplzstr>
    <kndtbkndname2 />
    <kndtbkndstrasse>In der Höh 8</kndtbkndstrasse>
    <kndtbkndortstr>Wadersloh</kndtbkndortstr>
    <kndtbkndtel>56673-54633</kndtbkndtel>
    <kndtbkndfax />
    <kndtbkndemail />
    <kndtbkndwww>www.3s-erp.de</kndtbkndwww>
    <kndtbkndmatchcode>Fritz &amp; Franz Bikes,</kndtbkndmatchcode>
    <kndtbkndlandpf>D</kndtbkndlandpf>
    <kndtbkndwaehrung>EUR</kndtbkndwaehrung>
    <kndtbkndlandstr>D</kndtbkndlandstr>
  </Table>
  <Table>
    <knd_entity_Id>2</knd_entity_Id>
    <CheckboxCol>0</CheckboxCol>
    <kndtbkndnr>4002</kndtbkndnr>
    <kndtbkndstatus>1</kndtbkndstatus>
    <kndtbkndname1>Fahrrad Leasing AG</kndtbkndname1>
    <kndtbkndname3 />
    <kndtbkndplzstr>53622</kndtbkndplzstr>
    <kndtbkndname2 />
    <kndtbkndstrasse>Auf dem Holz 8</kndtbkndstrasse>
    <kndtbkndortstr>Königswinter</kndtbkndortstr>
    <kndtbkndtel>0245-98521</kndtbkndtel>
    <kndtbkndfax />
    <kndtbkndemail />
    <kndtbkndwww />
    <kndtbkndmatchcode>Fahrrad Leasing AG,</kndtbkndmatchcode>
    <kndtbkndlandpf>D</kndtbkndlandpf>
    <kndtbkndwaehrung>EUR</kndtbkndwaehrung>
    <kndtbkndlandstr>D</kndtbkndlandstr>
  </Table>
</NewDataSet>

Where COntents inside the Tables are not fixed. they may very as per the Entity attributes. I need an Ilist from this XML using LInq to XML.

Kindly provide help.

Thanks and Regards, Ruchi Patel

4

1 回答 1

0

你可以试试下面的代码

public class Table
{
     public int EntityId {get;set;}
     public string CheckboxCol {get;set;}
     //TODO: Add rest of the properties
}

XElement element = XElement.Load("Your xml file path");  //replace with xml file path

if (element != null)
{
  IList<Table> result = (from e in element.Descendants("Table")
  select new Table
  {
     EntityId = int.Parse(e.Element("knd_entity_Id").Value),
     CheckboxCol= e.Element("CheckboxCol").Value //TODO: Add rest of the properties
  }).ToList();
}
于 2013-07-02T08:35:59.767 回答