다음을 통해 공유


IXMLDOMCDATASection

 

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

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

Jscript Example

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");  
var nodeCDATA;  
nodeCDATA = xmlDoc.createCDATASection("Hello");  
WScript.Echo(nodeCDATA.xml);  

C++ Example

#import "msxml6.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();  
}  
  

Output

<![CDATA[Hello]]>  

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:

msxml3.dll, msxml2.lib (MSXML 3.0)

msxml6.dll, msxml6.lib (MSXML 6.0)

Header and IDL files (C/C++): msxml2.h, msxml2.idl, msxml6.h, msxml6.idl

Versioning

Implemented in: MSXML 3.0, MSXML 6.0

See Also

normalize Method
IXMLDOMCDATASection Members
IXMLDOMElement
IXMLDOMText