Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created an xml file and i have to load the some stylesheetfile but its throwing error while loading style sheet file

What I have tried:

MSXML::IXMLDOMDocumentPtr loadXML;
m_hr = loadXML.CreateInstance(__uuidof(DOMDocument));
if (loadXML->load(variant_t(_T("Style.xsl"))) == VARIANT_FALSE)
{
    return false;    // returning false some times
}

xsl file contain
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="xml"/>
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
Posted
Updated 12-Jun-18 2:43am
v2

Using a file name without path may fail when the current working directory is not the same as when creating the file.

To know what went wrong use the IXMLDOMDocument::load[^] function that accepts two parameters and returns an HRESULT which can be used to retrieve an error message.
 
Share this answer
 
Comments
Member 13089825 12-Jun-18 8:32am    
file is in same directory
Jochen Arndt 12-Jun-18 8:40am    
Not the file must be in the "same" directory (whatever that means) but the working directory has to be the same. Because that can't be generally controlled, files should be always specified with full path.

However, what is the HRESULT when loading fails?
Only that will help you finding out why it fails.
Member 13089825 12-Jun-18 9:22am    
HRESULT hr= loadXML->load(variant_t(Style.xsl")));
if (FAILED(hr))
{//how to print error details here

return false;
}
could you please check it once
Jochen Arndt 12-Jun-18 10:32am    
You have to use the version from the link in my answer using a second "VARIANT_BOOL* varIsSuccessful" parameter or the code from Thaddeus' solution.

If you have a HRESULT code I can give you the error definition and message (at least tomorrow when back at work where I have a tool for that).
Check the error information provided when load() fails:

if (loadXML->load(variant_t(_T("Style.xsl"))) == VARIANT_FALSE)
{
		IXMLDOMParseErrorPtr errPtr = loadXML->GetparseError();  
		_bstr_t bstrErr(errPtr->reason);  

		printf("Error:\n");  
		printf("Code = 0x%x\n", errPtr->errorCode);  
		printf("Source = Line : %ld; Char : %ld\n", errPtr->line, errPtr->linepos);  
		printf("Error Description = %s\n", (char*)bstrErr); 

		return false;    // returning false some times
}
 
Share this answer
 
Comments
Member 13089825 12-Jun-18 9:16am    
source code line number showing empty
[no name] 12-Jun-18 9:23am    
Does it show an error code? The meaning of the error codes can be found at https://msdn.microsoft.com/en-us/library/jj134414(v=vs.85).aspx
Member 13089825 12-Jun-18 9:26am    
NO

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900