This is my XML schema,
<Modules>
<Module name="Sales" path="../SalesInfo.xml" isEnabled="true" ... >
..............
</Module>
<Module name="Purchase" path="../PurchaseInfo.xml" isEnabled="true" ... >
..............
</Module>
................
</Module>
</Modules>
SalesInfo.XML
<Screens>
<Screen name="SalesOrder" ........ />
</Screen>
public class Module
{
public string Name
{
get;
set;
}
public string Type
{
get;
set;
}
.....
}
Here the modules and Screens are loaded on Request basis ("On Demand"). So i have to find the particular node when request comes(may be from menu click). Once the node is picked, it need to be converted to particular class. Eg when "sales" request comes, it should picked from XML and that need to converted to "Module" class. As one possible way is
- Using XPathNavigator and find the Node.
- Parse the "Finded Node" and convert to Particular class
This is bit complicated. I have to take care of all the attribute and its datatypes.
What i looking for
- Find the Node
- Convert the Node to My custom Class (I doesn't want to write code for Parser)
What is the Best approach. I'm working on C# 4.0.
EDIT:
XDocument document = XDocument.Load(path);
XElement mod = document.XPathSelectElement("Modules/Module[@name='PurchaseEnquiry']") as XElement;
Module purchaseModule = mod as Module; //This won't work, but i want like this.