比如我想写上:
<?xml-stylesheet href="a.xsl" type="text/xsl" ?>怎么搞?

解决方案 »

  1.   

    谢谢,在MSDN上找了一段,
    并且仔细研读了一遍然后移植到我的源码中,
    但createProcessingInstruction和appendChild函数说我参数个数有误
    只好估摸着修改了参数个数,就产生了异常(AppendChild处)。
    这个是不是XML的版本差异性?我的MSDN版本2001JUL
    编译环境:WindowsXPsp2+VC6+SP5附:MSDN中的原文
    mk:@MSITStore:D:\Program%20Files\Microsoft%20Visual%20Studio\MSDN\2001JUL\1033Example
    #import "msxml3.dll"
    using namespace MSXML2;#define CHECK_AND_RELEASE(pInterface)  \
       if(pInterface) \
       {\
          pInterface->Release();\
          pInterface = NULL;\
       }\#define RELEASE(pInterface)  \
       {\
          pInterface->Release();\
          pInterface = NULL;\
       }\BOOL BuildDynamicXMLwithProcessingInstruction()
    {
       BOOL bResult = FALSE;
       IXMLDOMDocument *pIXMLDOMDocument=NULL;
       IXMLDOMElement *pIXMLDOMElement=NULL;
       IXMLDOMProcessingInstruction *pIXMLDOMProcessingInstruction=NULL;
       IXMLDOMNode *pIXMLDOMNode = NULL;
       HRESULT hr ;
       BSTR bstrValue ;   try
       {
          hr=CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_SERVER, 
    IID_IXMLDOMDocument2, (LPVOID*)(&pIXMLDOMDocument));
          SUCCEEDED(hr) ? 0 : throw hr;      if(pIXMLDOMDocument)
          {
             hr=pIXMLDOMDocument->createElement(_T("Node1"), &pIXMLDOMElement);
             if(SUCCEEDED(hr) && pIXMLDOMElement)
             {
                hr=pIXMLDOMElement->put_text(_T("test"));
                if(SUCCEEDED(hr))
                {
                   hr=pIXMLDOMDocument->createProcessingInstruction(_T("xml"),
     _T("version='1.0'"), &pIXMLDOMProcessingInstruction);
                   if(SUCCEEDED(hr) && pIXMLDOMProcessingInstruction)
                   {
                      pIXMLDOMDocument->appendChild( 
                                  pIXMLDOMProcessingInstruction, &pIXMLDOMNode);
                   pIXMLDOMDocument->putref_documentElement(pIXMLDOMElement);
                   hr=pIXMLDOMDocument->get_xml(&bstrValue);
                   if(SUCCEEDED(hr))
                   {
                   ::MessageBox(NULL, bstrValue, _T("Loaded Doc"), MB_OK);
                      bResult=TRUE;
                      }
                      CHECK_AND_RELEASE(pIXMLDOMNode);
                      RELEASE(pIXMLDOMProcessingInstruction);
                   }
                }
                RELEASE(pIXMLDOMElement);
             }
             RELEASE(pIXMLDOMDocument);
          }
       }
       catch(...)
       {
          CHECK_AND_RELEASE(pIXMLDOMElement);
          CHECK_AND_RELEASE(pIXMLDOMDocument);
          CHECK_AND_RELEASE(pIXMLDOMNode);
          CHECK_AND_RELEASE(pIXMLDOMProcessingInstruction);
          DisplayErrorToUser();
       }
       return bResult;
    }
    Output (in a message box)<?xml version="1.0"?>
    <Node1>test</Node1>
      

  2.   

    兄弟,为什么我按照你的代码调试会出现下面的错误信息?
    --------------------Configuration: FileStream - Win32 Debug--------------------
    Compiling...
    FileStreamDlg.cpp
    d:\microsoft visual studio\myprojects\filestream\filestreamdlg.cpp(4) : warning C4652: compiler option 'Generate Browser Info' inconsistent with precompiled header; current command-line option will override that defined in the precompiled header
    D:\Microsoft Visual Studio\MyProjects\FileStream\FileStreamDlg.cpp(285) : error C2664: 'createElement' : cannot convert parameter 1 from 'char [6]' to 'unsigned short *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    D:\Microsoft Visual Studio\MyProjects\FileStream\FileStreamDlg.cpp(288) : error C2664: 'put_text' : cannot convert parameter 1 from 'char [5]' to 'unsigned short *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    D:\Microsoft Visual Studio\MyProjects\FileStream\FileStreamDlg.cpp(292) : error C2664: 'createProcessingInstruction' : cannot convert parameter 1 from 'char [4]' to 'unsigned short *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Error executing cl.exe.FileStream.exe - 3 error(s), 1 warning(s)