Project DescriptionYet another easy to use C++ and C# XML parser library on Windows platform!
The code to create a simple XML, using C++ Elmax
using namespace Elmax;
Element root;
root.SetDomDoc(pDoc); // A empty DOM doc is initialized beforehand.
root[L"Books|Book|Price"].SetFloat(12.99f);
The almost similar code to create a simple XML, using C# Elmax
using Elmax;
Element root = new Element();
root.SetDomDoc(doc); // A empty DOM doc is initialized beforehand.
root["Books|Book|Price"].SetFloat(12.99f);
The end result (XML)
<Books>
<Book>
<Price>12.990000</Price>
</Book>
</Books>
The C++ code to read the price in that XML
using namespace Elmax;
Element root;
root.SetDomDoc(pDoc); // A XML file is read into the DOM doc beforehand.
Element elemPrice = root[L"Books|Book|Price"];
if(elemPrice.Exists())
{
float price = elemPrice.GetFloat(10.0f);
}
The similar C# code to read the price in that XML
using Elmax;
Element root = new Element();
root.SetDomDoc(doc); // A XML file is read into the DOM doc beforehand.
Element elemPrice = root["Books|Book|Price"];
if(elemPrice.Exists)
{
float price = elemPrice.GetFloat(10.0f);
}
An code example of Linq-to-XML Style of Node Creation in version 0.82 of C++ Elmax
using namespace Elmax;
NewElement root(L"Foods");
root.Add(
NewElement(L"Food",
NewAttribute(L"Name", L"Luncheon Meat"),
NewAttribute(L"Price", L"8.40"),
NewAttribute(L"Category", L"Grocery"),
NewElement(L"Manufacturer",
NewElement(L"Address", L"Jurong, Singapore"),
NewElement(L"Name", L"Acme Canned Food")
)
),
NewElement(L"Food",
NewAttribute(L"Name", L"Instant Noodle"),
NewAttribute(L"Price", L"12.30"),
NewAttribute(L"Category", L"Dried Food"),
NewElement(L"Manufacturer",
NewElement(L"Address", L"Ang Mo Kio, Singapore"),
NewElement(L"Name", L"Ah Kong Food Industrial")
)
)
);
root.PrettySave(szPath, L"1.0", true);
Here is the XML contents generated from the above Linq-to-XML Style of Node Creation code.
<?xml version="1.0" encoding="UTF-8"?>
<Foods>
<Food Name="Luncheon Meat" Price="8.40" Category="Grocery">
<Manufacturer>
<Address>Jurong, Singapore</Address>
<Name>Acme Canned Food</Name>
</Manufacturer>
</Food>
<Food Name="Instant Noodle" Price="12.30" Category="Dried Food">
<Manufacturer>
<Address>Ang Mo Kio, Singapore</Address>
<Name>Ah Kong Food Industrial</Name>
</Manufacturer>
</Food>
</Foods>
Tutorial at CodeProjectLinq-To-XML Node Creation Tutorial at CodeProjectDocumentation
Future Development
Version 1 is feature complete. Work has begun on the next version, cross-platform Elmax which would be rewritten from ground up and not using any Microsoft specific technologies. Version 1 and version 2 will be developed and maintained concurrently. Version 1 and version 2 codebase will be merged at some point in time, meaning version 1 will eventually ditch MSXML and use the cross-platform parser in version 2 but version 1 would continue to provide convenient accessor and mutator for some Microsoft data types like GUID and MFC CString.
Note : SAX and ORM version is put on hold because this project has not been generating many interest.