c# - processing Xnode with Linq efficiently -


i have xml node following format. node must converted userdefined type each node must convert object of myclass

class myclass {   public string tag1id {get;set;}   public int tag3val {get;set;}   public string tag3id {get;set;}   public int tag5val {get;set;}   public string tag5id {get;set;}   public datatime tag7val {get;set;}  }    <tag1 id="id1">      <tag2>        <tag3 id="id3">10</tag3>        <tag4>         <tag5 id="id5">20</tag5>        </tag4>      </tag2>      <tag6>       <tag7>2010-12-31</tag7>      </tag6>     </tag1> 

i new linq, can done using linq. requirement xmlseralization should not used :( there other approach scenario can handled easily?

no cannot done.

there must conversion done somewhere due business logic plumbing go specific properties exacting node ids/locations.

what can done code constructor takes in node , populates properties accordingly. linq can used enumerate on nodes , create new projection of class elements via select such as:

     string data = @" <tags>   <tag id=""id1"">       <tag2>         <tag3 id=""id3"">10</tag3>         <tag4>          <tag5 id=""id5"">20</tag5>         </tag4>       </tag2>       <tag6>        <tag7>2010-12-31</tag7>       </tag6>      </tag>  </tags>     "; var xml = xdocument.parse(data);      var classes = xml.descendants( "tag1" )                      .select( nd => new myclass( nd ) ); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -