Using MSXML Parser in the VC++ 2005 Express Edition
-
I know how to use the MS XML Parser in VC++ 6. For instance, I can do a #import the dll using the appropriate namespace. But this does not seem to work in VC++ 2005 Express Edition... What do I need to do so that I could use MSXML parser in my C++ sources which are to be compiled with the free VC++ 2005 Express Edition alone (and no other compiler)? Please provide pointers to any helpful articles/pages here or elsewhere. Thanks in advance.
---------- [" target="">http://www.JadhavResearch.info](http://www.JadhavResearch.info<br mode=)
-
I know how to use the MS XML Parser in VC++ 6. For instance, I can do a #import the dll using the appropriate namespace. But this does not seem to work in VC++ 2005 Express Edition... What do I need to do so that I could use MSXML parser in my C++ sources which are to be compiled with the free VC++ 2005 Express Edition alone (and no other compiler)? Please provide pointers to any helpful articles/pages here or elsewhere. Thanks in advance.
---------- [" target="">http://www.JadhavResearch.info](http://www.JadhavResearch.info<br mode=)
-
I know how to use the MS XML Parser in VC++ 6. For instance, I can do a #import the dll using the appropriate namespace. But this does not seem to work in VC++ 2005 Express Edition... What do I need to do so that I could use MSXML parser in my C++ sources which are to be compiled with the free VC++ 2005 Express Edition alone (and no other compiler)? Please provide pointers to any helpful articles/pages here or elsewhere. Thanks in advance.
---------- [" target="">http://www.JadhavResearch.info](http://www.JadhavResearch.info<br mode=)
To use #import with an Express edition, you need to remove any mention of ATL (as the express editions don't ship with ATL). That means no smart pointers, no wrappers for
VARIANT
orBSTR
. You can tell#import
not to use ATL with attributes (see the second example below). So, it can be done, but it means going from code like this:#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
#include <atlbase.h>
#include <atlstr.h>#include <iostream>
#import progid:Msxml2.DOMDocument.6.0 rename_namespace("TestNS")
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(0, COINIT_MULTITHREADED);
TestNS::IXMLDOMDocument3Ptr pDoc(__uuidof(TestNS::FreeThreadedDOMDocument60));pDoc->load("CHange-History.xml");
pDoc->setProperty("SelectionLanguage", "XPath");
TestNS::IXMLDOMNodeListPtr selected = pDoc->documentElement->selectNodes("//configuration");
long nodeCount;
selected->get_length(&nodeCount);
std::cout << nodeCount << " configuration nodes\n";
CoUninitialize();
return 0;
}to code like this (it runs and gives the same answer as the code above, but I'm not sure that I manage resources correctly....
#include <tchar.h>
#include <iostream>#import progid:Msxml2.DOMDocument.6.0 rename_namespace("TestNS") raw_interfaces_only no_implementation no_smart_pointers raw_native_types
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(0, COINIT_MULTITHREADED);
TestNS::IXMLDOMDocument3* pDoc;
HRESULT hr;if (SUCCEEDED(hr = ::CoCreateInstance(__uuidof(TestNS::FreeThreadedDOMDocument60), 0, CLSCTX_ALL, __uuidof(TestNS::IXMLDOMDocument3), (void**)&pDoc)))
{
BSTR file = ::SysAllocString(L"CHange-History.xml");
VARIANT vFile;
V_VT(&vFile) = VT_BSTR;
V_BSTR(&vFile) = file;
VARIANT_BOOL loadedOK;
if (SUCCEEDED(hr = pDoc->load(vFile, &loadedOK) && loadedOK == VARIANT_TRUE))
{
BSTR propName = ::SysAllocString(L"SelectionLanguage");
BSTR selectionLanguage = ::SysAllocString(L"XPath");
VARIANT vSelLang;
V_VT(&vSelLang) = VT_BSTR;
V_BSTR(&vSelLang) = selectionLanguage;
TestNS::IXMLDOMElement* docElement;
BSTR xpath = ::SysAllocString(L"//configuration");
TestNS::IXMLDOMNodeList* selected; -
To use #import with an Express edition, you need to remove any mention of ATL (as the express editions don't ship with ATL). That means no smart pointers, no wrappers for
VARIANT
orBSTR
. You can tell#import
not to use ATL with attributes (see the second example below). So, it can be done, but it means going from code like this:#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
#include <atlbase.h>
#include <atlstr.h>#include <iostream>
#import progid:Msxml2.DOMDocument.6.0 rename_namespace("TestNS")
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(0, COINIT_MULTITHREADED);
TestNS::IXMLDOMDocument3Ptr pDoc(__uuidof(TestNS::FreeThreadedDOMDocument60));pDoc->load("CHange-History.xml");
pDoc->setProperty("SelectionLanguage", "XPath");
TestNS::IXMLDOMNodeListPtr selected = pDoc->documentElement->selectNodes("//configuration");
long nodeCount;
selected->get_length(&nodeCount);
std::cout << nodeCount << " configuration nodes\n";
CoUninitialize();
return 0;
}to code like this (it runs and gives the same answer as the code above, but I'm not sure that I manage resources correctly....
#include <tchar.h>
#include <iostream>#import progid:Msxml2.DOMDocument.6.0 rename_namespace("TestNS") raw_interfaces_only no_implementation no_smart_pointers raw_native_types
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(0, COINIT_MULTITHREADED);
TestNS::IXMLDOMDocument3* pDoc;
HRESULT hr;if (SUCCEEDED(hr = ::CoCreateInstance(__uuidof(TestNS::FreeThreadedDOMDocument60), 0, CLSCTX_ALL, __uuidof(TestNS::IXMLDOMDocument3), (void**)&pDoc)))
{
BSTR file = ::SysAllocString(L"CHange-History.xml");
VARIANT vFile;
V_VT(&vFile) = VT_BSTR;
V_BSTR(&vFile) = file;
VARIANT_BOOL loadedOK;
if (SUCCEEDED(hr = pDoc->load(vFile, &loadedOK) && loadedOK == VARIANT_TRUE))
{
BSTR propName = ::SysAllocString(L"SelectionLanguage");
BSTR selectionLanguage = ::SysAllocString(L"XPath");
VARIANT vSelLang;
V_VT(&vSelLang) = VT_BSTR;
V_BSTR(&vSelLang) = selectionLanguage;
TestNS::IXMLDOMElement* docElement;
BSTR xpath = ::SysAllocString(L"//configuration");
TestNS::IXMLDOMNodeList* selected;Thanks, Stuart! BTW, in the meanwhile, I have already made use of TinyXML because my requirements were very very simple. My document has a very simple (and predictable) structure that is just two/three levels deep... It doesn't have to to have validation... Why TinyXML? Because, Google showed it above the others, that's why... Thanks again, anyway, and bye for now
---------- http://www.JadhavResearch.info
-
Thanks, Stuart! BTW, in the meanwhile, I have already made use of TinyXML because my requirements were very very simple. My document has a very simple (and predictable) structure that is just two/three levels deep... It doesn't have to to have validation... Why TinyXML? Because, Google showed it above the others, that's why... Thanks again, anyway, and bye for now
---------- http://www.JadhavResearch.info
Ajit Jadhav wrote:
TinyXML
Sounds like the right thing for your scenario. Another option that might have suited you is RapidXML[^] - it's so small that it's contained in a single header file you
#include
into your code! [edit]Or Microsoft's XmlLite[^], possibly[/edit]Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p