I’d like to convert an external XML document without any XSD schema associated with it into a fluent .NET object.
I have a simple XML file like:
<application> <parameters> <param></param> <param></param> </parameters> <generation /> <entities> <entity ID='1'> <PropTest>Test</PropTest> </entity> <entity ID='2'> <PropTest>Another Test</PropTest> </entity> </entities> </application>
I’d like to navigate the document like:
var xConfig = new XmlConfig('file.xml'); // testValue should be assigned 'Test' string testValue = xConfig.Generation.Entities.Entity(1).PropTest;
What is the best way to achieve this in .NET 3.5?
Arguably, the best way to do this these days is with Linq to XML. It is a whole lot easier than messing with XSDs and convoluted class definitions.
The sample file.xml that I used was: