troubleshooting Question

TransformNode() MSXML using C++ doesn't work

Avatar of Vikur
Vikur asked on
XML
11 Comments1 Solution1807 ViewsLast Modified:
Hi,
A following code retutn exeption on loadXML function. What is wrong ?


#include <windows.h>
#import  <msxml3.dll>

typedef MSXML2::IXMLDOMDocumentPtr     DocPtr;
typedef MSXML2::IXMLDOMNodePtr            NodePtr;

void get_error(DocPtr doc)
{
      MSXML2::IXMLDOMParseErrorPtr  pErr = doc->GetparseError();//parseError;  
       if( pErr->GeterrorCode() != 0)
          throw pErr->Getreason();
       else
          AfxMessageBox ("loaded successfuly");
}

///////////////////////////////////////
void tform(char* c_args)
{
     CoInitialize(NULL);
   try
   {      
       DocPtr xmlDoc(__uuidof(MSXML2::DOMDocument));
//This loads the text that I want to transform
       xmlDoc->load(c_args);      
       get_error(xmlDoc);
//This loads the XSLT transform
       DocPtr xslDoc(__uuidof(MSXML2::DOMDocument));
          xslDoc->load("sam1.xsl");
       get_error(xmlDoc);
//This transforms

     DocPtr xmlDso(__uuidof(MSXML2::DOMDocument));

     NodePtr xmlroot = xmlDoc->GetdocumentElement();
     NodePtr xslroot = xslDoc->GetdocumentElement();
     _bstr_t str = xmlroot->transformNode(xslroot) ;
// THERE IS FAULT OCCURE
 xmlDso->loadXML(str);
     get_error(xmlDso);
     xmlDso->save("newFile.xml");

   }
   catch(char* lpstrErr) {
          // Some error...
          AfxMessageBox(lpstrErr );
   }      catch(...) {
          // Unknown error...
          AfxMessageBox("Unknown error..." );
     }

   CoUninitialize();
}

/////////////////////////////////////

<?xml version="1.0" encoding="UTF-8"?>

<source>
<title>XSL</title>
<author>John Smith</author>
</source>

/////////////////////////////////////////////

<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/">
     <h1>
          <xsl:value-of select="//title"/>
     </h1>
     <h2>
          <xsl:value-of select="//author"/>
     </h2>
</xsl:template>

</xsl:stylesheet>
ASKER CERTIFIED SOLUTION
BigRat

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros