다음을 통해 공유


IXMLDOMProcessingInstruction

 

Represents a processing instruction, which XML defines to keep processor-specific information in the text of the document.

JScript Example

The following JScript example creates a new IXMLDOMProcessingInstruction object and displays its XML representation.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");  
var pi;  
pi = xmlDoc.createProcessingInstruction("xml", "version=\"1.0\"");  
WScript.Echo(pi.xml);  
  

Output

The example produces the following output in a message box.

<?xml version="1.0"?>

C++ Example

#include “msxml6.h”  
#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(CComBSTR(L"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,L"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

The C++ example produces the following output in a message box.

<?xml version="1.0"?>

<Node1>test</Node1>

Remarks

The content of the ProcessingInstruction node is the entire content between the delimiters of the processing instruction.

The content of this node is usually subdivided into the target (the application to which this processing instruction is directed) and the content of the processing instruction. The target consists of the first token following the start of the tag, while the content of the processing instruction refers to the text that extends from the first non-white space character after the target through the character immediately preceding the ?>, which signifies the end of the tag.

Requirements

Implementation:

msxml3.dll, msxml2.lib (MSXML 3.0)

msxml6.dll, msxml6.lib (MSXML 6.0)

Header and IDL files:

msxml2.h, msxml2.idl, msxml6.h, msxml6.idl

Versioning

Implemented in:

MSXML 3.0, MSXML 6.0

See Also

IXMLDOMDocument-DOMDocument
IXMLDOMProcessingInstruction Members