IXMLDOMCDATASection

MSXML 5.0 SDK

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

IXMLDOMCDATASection

Used to quote or escape blocks of text to keep that text from being interpreted as markup language.

[C/C++]

Although the IXMLDOMCDATASection inherits IXMLDOMText, unlike text nodes, the normalize method of IXMLDOMElement does not merge CDATASection nodes.

[Script]

Example

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var nodeCDATA;
nodeCDATA = xmlDoc.createCDATASection("Hello");
alert(nodeCDATA.xml);
[Visual Basic]

Example

Dim xmlDoc As New Msxml2.DOMDocument50
Dim nodeCDATA As IXMLDOMCDATASection
Set nodeCDATA = xmlDoc.createCDATASection("Hello")
MsgBox nodeCDATA.xml
[C/C++]

Example

The following C/C++ example creates and appends a new CDATASection node to the root document element.

#import "msxml5.dll"
using namespace MSXML2;

inline void TESTHR( HRESULT _hr ) 
   { if FAILED(_hr) throw(_hr); }


void XMLDOMCDATASectionSample()
{
   try {
      IXMLDOMDocumentPtr docPtr;
      IXMLDOMNodePtr DOMNodePtr;

      //init
      TESTHR(CoInitialize(NULL)); 
      TESTHR(docPtr.CreateInstance("msxml2.domdocument"));
      
      // load a document
      _variant_t varXml("C:\\book.xml");
      _variant_t varOut((bool)TRUE);
      varOut = docPtr->load(varXml);
      if ((bool)varOut == FALSE)
         throw(0);
      MessageBox(NULL, _bstr_t(docPtr->xml), _T("Original Document"), MB_OK);

      DOMNodePtr = docPtr->createCDATASection("<fragment>XML tags 
inside a CDATA section</fragment>");
      docPtr->documentElement->appendChild(DOMNodePtr);

      MessageBox(NULL, _bstr_t(docPtr->xml), _T("New Document"), MB_OK);

   } catch(...)
   {
      MessageBox(NULL, _T("Exception occurred"), _T("Error"), MB_OK);
   }
   CoUninitialize();
}

Remarks

CDATA sections let you include material such as XML fragments within XML documents without needing to escape all the delimiters. The only delimiter recognized in a CDATA section is the "]]>" string that ends the CDATA section.

CDATA sections cannot be nested.

The text contained by the CDATA section is stored in a text node. This text can contain characters that need to be escaped outside of CDATA sections.

IXMLDOMCDATASection has no unique members of its own, but exposes the same members as the IXMLDOMText object.

Requirements

Implementation: msxml5.dll, msxml2.lib

[C/C++]

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

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

See Also

normalize Method | IXMLDOMCDATASection Members | IXMLDOMElement | IXMLDOMText