| ||||||||
CDATA SectionsCDATA Sections designate an area in the XML document where Standard Special Characters are not escaped and whitespace is preserved. They are commonly used for putting chunks of HTML inside an XML document, or to preserve whitespace and line feeds in a data value when the document is transferred between XML tools. Use CDATA Sections for anything containing markup that must be ignored by the rest of the XML document but is nice to keep legible for when the XML document is viewed in a text editor. Although Node Methods in CMarkup support individual CDATA Sections explicitly, CDATA Sections are best used inside of elements with SetData and GetData. The part about CDATA Sections that no one wants to worry about is whether your data happens to contain the delimiter
I recommend having the CDATA Section inside it's own element (with a tag name such as Data), just like any other element where you use it's content as a single data value. CMarkup can do mixed content such as an element containing both a CDATA Section and an element, but it is less convenient for you. The normal and safe way to use a CDATA Section in CMarkup is to add an element using the CDATA Section flag CMarkup xml; CString str = "the <B>red</B> fox jumps"; xml.AddElem( "Data", str, CMarkup::MNF_WITHCDATA ); In early releases of CMarkup before xml.AddElem( "Data" ); xml.SetData( str, CMarkup::MNF_WITHCDATA ); In either case, an element is generated containing data in a CDATA Section. The second argument <Data><![CDATA[the <B>red</B> fox jumps]]></Data>
Later the data can be retrieved without concern about whether it is in a CDATA Section. xml.FindElem( "Data" ); str = xml.GetData(); These element data methods allow you to avoid node methods, and automate placing the CDATA Section inside the element (as a child node of the element). Calling To use Node Methods in CMarkup as you showed, the key to putting a node inside the current main element is that you need to go into the element (IntoElem) before calling AddNode. To get data from a specific CDATA Section using node methods, navigate using FindNode and then | ||||||
|
Posted June 3, 2004 updated June 2, 2005. Question or comment about this article? ©Copyright 2008 First Objective Software, Inc. All rights reserved. |