Unable to use latest generated xml file with XALAN Transform C++

  c++, xalan, xerces, xml, xslt

I’m trying to transform XML, XSL to html using Apache xalan-C++ framework

I’m generating the xml file based on a template xml using xerces parser. sFinalXMLPath refers the file name or full file path of the xml file generated.

I’m using the generated xml file name or full file path, it fails. But after program execution, hardcoded the file name, it is working.

Error message:
enter image description here

Code:

XSLTInputSource xmlIn(sFinalXMLPath.c_str());
std::string xsltFilePath = sTemplateDir + "test_mail.xsl";
std::string htmlFilePath = sTemplateDir + "test_mail.html";
XSLTInputSource xslIn(xsltFilePath.c_str());
XSLTResultTarget xmlOut(htmlFilePath.c_str());
int theResult = theXalanTransformer.transform(xmlIn, xslIn, xmlOut);

Code to generate to xml:

std::string xmlFileName = AppendTimeToFileName("mail_xml_input.xml");
//tcTempLoc += fs::path::preferred_separator;
tcTempLoc += "/";
std::string sFinalXMLPath = tcTempLoc + xmlFileName;

cout << "nTemplate XML Path: " << xmlFilePath;
cout << "nFinal XML Path: " << sFinalXMLPath;
fs::copy_file(xmlFilePath, sFinalXMLPath);

// Build input xml
XmlDomDocument* xFinalXMLInput = new XmlDomDocument(sFinalXMLPath.c_str());
string sValuetoSet;
if (xFinalXMLInput) {
    for (int i = 0; i < xFinalXMLInput->getChildCount("Overview", 0, "Entry"); i++) {
        for (int j = 0; j < xFinalXMLInput->getChildCount("Entry", i, "property"); j++) {
            sAttrName = xFinalXMLInput->getChildAttribute("Entry", i, "property", j, "value");
            sValuetoSet = mProps[sAttrName];
            cout << "nValue to set for " << sAttrName << " is : " << sValuetoSet;
            iResult = xFinalXMLInput->setChildAttribute("Entry", i, "property", j, "value", sValuetoSet.c_str());
            sAttrName = xFinalXMLInput->getChildAttribute("Entry", i, "property", j, "value");
            cout << "nValue replaced : " << sAttrName;
        }
    }
}

xFinalXMLInput->normalizeDocument();
xFinalXMLInput->DoOutput2File(sFinalXMLPath.c_str());
delete xFinalXMLInput;

Source: Windows Questions C++

LEAVE A COMMENT