Basic C# .NET XML parser
This is a basic XML parser that reads XML from a file and turns it into a C# object. It is not very extensible and I have just implemented it to try and learn about how dynamic objects work in C#.
As of current it only supports a few features:
- Loading XML into a dynamic objects
- Querying the object by the . Member access operator
- Querying the object by the [int:index] operator
As of current there is no support for Attributes.
git clone https://github.com/Wamadahama/basic-xml-parser.git
Open the .sln
in Visual Studio and select Build and Run
git clone https://github.com/Wamadahama/basic-xml-parser.git
cd basic-xml-parser
sh install-linux.sh
Use dotnet run to use.
This sample XML document will be used to demonstrate the features of the parser
<?xml version="1.0" encoding="utf-8" ?>
<sample>
<foo>2</foo>
<bar>3</bar>
<foobar>
<foo>bar</foo>
<bar>foo</bar>
</foobar>
<foobarbazz>
<foo>1</foo>
<bar>2</bar>
<bazz>3</bazz>
</foobarbazz>
</sample>
Add DynamicXmlObject.cs
to your project (I have yet to make this into a class library because of the size)
and inlcude the Namespace with
using XmlParser;
dynamic Test = new DynamicXmlObject(@"Path/To/File.xml");
Console.WriteLine(Test.bar.ToString()); // => 3
Console.WriteLine(Test.foobar.foo); // => bar
Console.WriteLine(Test.foobar[0].ToString()); // => bar
List<string> Foobar = Test.foobar.ToList();
Foobar.ForEach((elem) => { Console.WriteLine(elem.ToString()); }); // => bar\nfoo\n