MSXML DLL:msxml3.dll
我正在使用 MSXML DOM 编写 XML,并希望添加多个处理指令。前任:
第一条处理指令。
xml version="1.0" encoding="ISO-8859-1"?
二次加工指令
xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?
我使用 MSXML DOM 编写了以下代码。但它未能添加第一和第二个处理指令。
代码开始
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);
请帮助理解为什么 MSXML 不添加多个处理指令?