I have xml Node with following format. This node must be converted to userdefined type that is each node must convert to object of say 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 am new to linq, Can it be done using linq. Requirement is xmlseralization should not be used 🙁
Is there any other approach by which this scenario can be handled easily?
No it cannot be done.
There must be a conversion done somewhere due to the business logic plumbing to go to the specific properties from the exacting node ids/locations.
What can be done is to code a constructor which takes in the node and populates the properties accordingly. Linq can then be used to enumerate over the nodes and create a new projection of the class elements via select such as: