Reputation: 86729
I'm using IXMLDOMDocument::transformNode
to apply an XSLT transform using C++ code that looks a little bit like this:
CComPtr<IXMLDOMDocument2> spXMLDoc;
// load spXMLDoc
CComPtr<IXMLDOMDocument2> spXSLDoc;
// load spXSLDoc
BSTR *pResult;
HRESULT hr = spXMLDoc->transformNode( spXSLDoc, pResult );
if (FAILED(hr))
{
// Handle me
}
This code works, however if the transform fails then I don't know how to get any information about where or why it failed - at the moment its failing (on a complex XSLT with multiple includes) with a HRESULT of E_FAIL
- is there any way I can get some more detail on why its failing?
I've already tried the parseError
property to get more error detail:
IXMLDOMParseError *parseError = NULL;
hr = spXMLDoc->get_parseError(&parseError);
if ( !FAILED( hr ) )
{
long errorCode = 0;
hr = parseError->get_errorCode(&errorCode);
// etc...
The call to get_parseError
succeeds, however the call to get_errorCode
fails with HRESULT S_FALSE
, indicating that there was not a parse error. This page tells me that there are two types of error - parse errors and runtime errors. It shows how to handle both, however appears to be JavaScript oriented - in my case no C++ runtime errors are thrown.
Upvotes: 3
Views: 1572
Reputation: 2923
Sorry, I'm not sure from C++. You might try a quick command line transformation to help find the error in XSLT. There's a number of errors where the XSL will load, but can't transform. For an example pop an somewhere in the XSL file to trigger this type of error.
Here's a sample command line transformation tool. Write to transform.js and run cscript.exe transform.js from a command line
var strDOMObject = "MSXML2.FreeThreadedDOMDocument";
var strHTTPObject = "MSXML2.XMLHTTP";
var strTemplateObject = "MSXML2.XSLTemplate";
function transform( xml, xsl ) {
var xslt = new ActiveXObject( strTemplateObject );
var xmlReturn = new ActiveXObject( strDOMObject );
var xslProc;
try {
xslt.stylesheet = xsl;
} catch( e ) {
throw e;
}
xslProc = xslt.createProcessor();
xslProc.input = xml;
xslProc.transform();
return xslProc.output;
}
try {
var xml = new ActiveXObject( strDOMObject );
xml.load( "id.xml" );
var xsl = new ActiveXObject( strDOMObject );
xsl.load( "id.xsl" );
WScript.Echo( transform( xml, xsl ) );
} catch( err ) {
WScript.Echo (err.description );
}
Hope this helps, and that you can find out the C++ answer.
Upvotes: -1