Represents a processing instruction, which XML defines to keep processor-specific information in the text of the document.
This interface inherits from IXMLDOMNode.
data | Stores the content of the processing instruction, excluding the target. |
target | Specifies the target—the application to which this processing instruction is directed. |
The content of the ProcessingInstruction node is the entire content between the delimiters of the processing instruction (PI).
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 PI refers to the text that extends from the first nonwhite-space character after the target through the character immediately preceding the ?>, which signifies the end of the tag.
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 messagebox)
<?xml version="1.0"?> <Node1>test</Node1>
Implementation: Msxml.dll
Header and IDL files: Msxml.h, Xmldom.idl