In previous post, I talked about how to use Libxml2 library to read/write xml files. Actually, there are many Free C or C++ XML Parser Libraries. From now no, I will turn to MSXML instead because of Libxml2’s poor support for Windows-x64 systems.
In the followings, I will show how to use MSXML to read/write xml files.
Pre-work:
To install MSXML is quite easy, you just need to install Windows SDK, where it is integrated.
Add #import <msxml3.dll> to the beginning part of your code.
For example, we want to load the above xml data to a vector<pair<int, float>> (name to a string), do like the following code, where input parameter gives the path of above xml file.
//read XML MSXML2::IXMLDOMDocumentPtr spXMLDoc; MSXML2::IXMLDOMElementPtr spRoot; HRESULT hr = spXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30));
if (!SUCCEEDED(hr)) printf("Unable to create xml file.\n"); else { spXMLDoc->raw_createElement((_bstr_t)"Appearance_model", &spRoot); spXMLDoc->raw_appendChild(spRoot, NULL);