0

I've made a project basing on this document to retrieve information from XML file basing on XSL file.
I am trying to throw an error in XSL file:

<xsl:if test="not(PIN/Length/text() = '4')">
    <xsl:message terminate="yes">PIN length in input suppose to be 4</xsl:message>
</xsl:if>

But it seems not to work (no errors during work) - just like it is successfully done.
Can I somehow catch this message in C++?

void ManageXML::XML2Generic(string sOrgFilePath, string sOrgXSLFilePath, string sCpfPath)
{
    wstring sTempFilePath = s2ws(sOrgFilePath);
    LPCWSTR sFilePath = sTempFilePath.c_str();

    wstring sTempXSLFilePath = s2ws(sOrgXSLFilePath);
    LPCWSTR sXSLFilePath = sTempXSLFilePath.c_str();

    HRESULT hr = S_OK;
    IXMLDOMDocument *pXMLDom = nullptr;
    IXMLDOMDocument *pXSLDoc = nullptr;

    CHK_HR(CreateAndInitParserDOM(&pXMLDom));
    CHK_HR(LoadXMLFile(pXMLDom, sFilePath, sOrgFilePath)); //cast to LPCWSTR
    CHK_HR(CreateAndInitParserDOM(&pXSLDoc));
    CHK_HR(LoadXMLFile(pXSLDoc, sXSLFilePath, sOrgXSLFilePath)); //cast to LPCWSTR

    // Transform dom to a string:
    CHK_HR(TransformDOM2Data(pXMLDom, pXSLDoc, sGenericResult));

CleanUp:
    SAFE_RELEASE(pXSLDoc);
    SAFE_RELEASE(pXMLDom);
    this->CreateGenericFile(sCpfPath);
    CoUninitialize();
}

One bad solution that comes to my mind is to make XSL like this:

<xsl:if test="not(PIN/Length/text() = '4')">
    <xsl:text>MSXML_ERROR: PIN length in input suppose to be 4</xsl:message>
</xsl:if>

And

CleanUp:
    SAFE_RELEASE(pXSLDoc);
    SAFE_RELEASE(pXMLDom);
    if (sGenericResult.find("MSXML_ERROR") != string::npos)
        throw runtime_error("blah blah blah");
    this->CreateGenericFile(sCpfPath);
    CoUninitialize();
Marek
  • 1,189
  • 3
  • 13
  • 33
  • You have ``CoUninitialize()`` in your code but no ``CoInitialize()`` or ``CoInitializeEx()``. Are you sure that ``CreateAndInitParserDOM()`` does that for you? – BitTickler Oct 14 '16 at 10:34
  • In the constructor there is: `HRESULT hr = CoInitialize(nullptr);` – Marek Oct 14 '16 at 10:41
  • 1
    There is no standard XSLT parser that's included in the standard C++ library, and, unfortunately, there is no universal answer that applies to every separate XSLT parsing library that's in use on the third planet from the sun (there's more than one, you know). You seem to be completely unaware of the fundamental fact that to answer a question like that, you have to specify which xslt parsing library you're using. – Sam Varshavchik Oct 14 '16 at 11:03
  • @SamVarshavchik My guess would be it is some form of wrapper around msxml. https://msdn.microsoft.com/en-us/library/ms759192(v=vs.85).aspx or rather the code sample you can also find here: https://msdn.microsoft.com/en-us/library/ms757821(v=vs.85).aspx – BitTickler Oct 14 '16 at 11:32
  • It is msxml. These are my imports: `#include #include #include #pragma comment(lib,"comsuppw.lib")`. Also this info is in the document I've sent. – Marek Oct 14 '16 at 11:33
  • Anything anybody? – Marek Oct 17 '16 at 06:45
  • You need to try/catch . As described in the MSXML SDK documentation, the error produced is: "0xC00CE30A MSG_E_SYSTEM_ERROR System error: %1." For more information: https://msdn.microsoft.com/en-us/library/jj134413(v=vs.85).aspx – Dimitre Novatchev Oct 22 '16 at 03:01
  • And what actually do I embedd in this try? – Marek Oct 26 '16 at 10:04

0 Answers0