MSXML DLL : #import <msxml3.dll>
I am writing XML using MSXML DOM & expected to add multiple processing instruction.
ex:

<?xml version="1.0" encoding="ISO-8859-1"?>          ------ first processing instruction.
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>  ------ second processing instruction.
<catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
</catalog>

I have write below code using MSXML DOM. But it failed to add first & second processing instruction.

MSXML2::IXMLDOMElementPtr pXMLRootElem; 
        MSXML2::IXMLDOMNodePtr pTestDOMNodePtr ;
        //Create an instance of the DOMDocument object:
        m_docPtr.CreateInstance(__uuidof(MSXML2::DOMDocument30));
        char* xmlfile =  (char*)xmlFileFullPath.c_str();
        _variant_t varXml(xmlfile); //XML file to load
        m_docPtr->async = VARIANT_FALSE;
        m_docPtr->validateOnParse = VARIANT_FALSE;
        m_docPtr->resolveExternals = VARIANT_FALSE;
        //load XML file.
        if(m_docPtr->loadXML(_T("<catalog><cd></cd></catalog>")) == VARIANT_FALSE)
        {
            CCommonFunction::log ("Failed to create the XML file.");
            return false;
        }
        //Get the root element just created    
        pXMLRootElem = m_docPtr->GetdocumentElement();
        //// Add first ProcessingInstruction <?xml version="1.0" encoding="ISO-8859-1"?>
        MSXML2::IXMLDOMProcessingInstructionPtr pXMLProcessingNode =  
              m_docPtr->createProcessingInstruction("xml", " version='1.0' encoding='UTF-8'");
        _variant_t vtObject;
        vtObject.vt = VT_DISPATCH;
        vtObject.pdispVal = pXMLRootElem;
        vtObject.pdispVal->AddRef();
        m_docPtr->insertBefore(pXMLProcessingNode,vtObject);

        //// Add second ProcessingInstruction <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
        MSXML2::IXMLDOMProcessingInstructionPtr pXSLTNode =  
        m_docPtr->createProcessingInstruction("xml-stylesheet", "type='text/xsl' href='cdcatalog.xsl'");
        m_docPtr->insertBefore(pXSLTNode,vtObject);

Please help in understanding why MSXML is not adding multiple processing instruction ?

Edited 3 Years Ago by Sandy20: no

I found the solution.

//Add first processing instruction
MSXML2::IXMLDOMProcessingInstructionPtr ptrPI = m_docPtr->createProcessingInstruction(L"xml", L"version='1.0' encoding='UTF-8'");

m_docPtr->insertBefore(ptrPI, m_docPtr->documentElement.GetInterfacePtr());

//Add second processing instruction
MSXML2::IXMLDOMProcessingInstructionPtr ptrPI1 = m_docPtr->createProcessingInstruction(L"xml-stylesheet", L"type='text/xsl' href='TestCaseFrameWork.xsl");

m_docPtr->insertBefore(ptrPI1, m_docPtr->documentElement.GetInterfacePtr());
This question has already been answered. Start a new discussion instead.