IXMLDOMProcessingInstruction

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

IXMLDOMProcessingInstruction

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

[Script]

Example

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

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var pi;
pi = xmlDoc.createProcessingInstruction("xml", "version=\"1.0\"");
alert(pi.xml);

Output (in a message box)

<?xml version="1.0"?>
[Visual Basic]

Example

The following Microsoft® Visual Basic® example creates a new IXMLDOMProcessingInstruction object and displays its XML representation.

Dim xmlDoc As New Msxml2.DOMDocument50
Dim pi As IXMLDOMProcessingInstruction
Set pi = xmlDoc.createProcessingInstruction("xml", "version=""1.0""")
MsgBox pi.xml

Output (in a message box)

<?xml version="1.0"?>

[C/C++]

Example

#import "msxml5.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(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 (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.

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

Versioning

MSXML 2.0 and later

Requirements

Implementation: msxml5.dll, msxml2.lib

[C/C++]

Header and IDL files: msxml2.h, msxml2.idl

See Also

DOMDocument | IXMLDOMProcessingInstruction Members