Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Using MSXML Parser in the VC++ 2005 Express Edition

Using MSXML Parser in the VC++ 2005 Express Edition

Scheduled Pinned Locked Moved C / C++ / MFC
c++xmltutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ajit Jadhav
    wrote on last edited by
    #1

    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=)

    E S 2 Replies Last reply
    0
    • A Ajit Jadhav

      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=)

      E Offline
      E Offline
      Eytukan
      wrote on last edited by
      #2

      What's the error you are getting? when you do an import in VS2005?


      OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

      1 Reply Last reply
      0
      • A Ajit Jadhav

        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=)

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #3

        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 or BSTR. 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;

        A 1 Reply Last reply
        0
        • S Stuart Dootson

          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 or BSTR. 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;

          A Offline
          A Offline
          Ajit Jadhav
          wrote on last edited by
          #4

          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

          S 1 Reply Last reply
          0
          • A Ajit Jadhav

            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

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups