MCD_STR CMarkup::GetData() const;

The GetData method returns the string data value of the main position element or node. It returns an empty string if there is no data value, or there is no current position, or the main position element contains child elements.

To get the markup string content of the main position element, see the GetElemContent method. To get the markup string subdocument rooted in the main position element see the GetSubDoc method.

Update November 20, 2010: With release 11.3 CMarkup has document flags to trim whitespace and collapse whitespace which will affect the value returned by GetData (see Whitespace and CMarkup).

Update March 24, 2009: GetData can be used with CMarkup release 11.0 developer version file read mode (see C++ XML reader).

Combined text data value

The text data in an element may be in a CData Section in which case GetData returns the content of the CDATA section.


GetData concatenates any combination of text and CDATA Section nodes in the content of the element, discarding any XML comments and processing instructions. As described for the SetData method, consecutive CDATA Sections in the content of the main position element will be concatenated and returned by GetData as one data string. This supports rare cases in which CDATA Sections are split to store data containing the ]]> end delimiter. The SetData method splits the data after the second bracket, other XML tools may place the end delimiter as a text node between the CDATA Sections. In both of the following EQUATION element examples, GetData returns "a]]>a".


Other node types

If the main position is at a node other than an element, GetData returns the "data" portion of the node:

Node Type Data
Comment the text between the double dashes
Processing Instruction the text between the question marks, including the target
Document Type the entire DTD including the beginning < and ending >
CDATA Section the text between the inner brackets
Text the text between tags
Whitespace the whitespace text between tags

See the Node Methods in CMarkup.