CMarkup FindSetData Method

bool FindSetData( MCD_CSTR szName, MCD_CSTR szData, int nFlags = 0 );

CMarkup Developer License

FindSetData is only in CMarkup Developer.

The FindSetData method combines FindElem and SetData into one convenient method, plus in release 9.0 it will create the element if it doesn't exist.

It finds or creates the element, sets that element as the main position element, and replaces the new main position element's contents with the szData string data value. This will remove any child elements of the main position element if any. It returns false if it does not find or create the element.

With the path for the szName argument as described in the FindElem method, this is a powerful way to set a data value in a document without several navigation calls. See more information about this under the FindGetData method documentation. For example, calling FindSetData("/Configuration/ShowUser","0") sets the Default element data value to 0.

Together with the FindGetData method, this is ideal for keeping configuration and messaging structures in XML documents. See Dynamic Structure Documents.

In order to create a non-existing element, a simple absolute path with no predicates must be specified. It will even create the parent elements necessary up to the leaf element. In the following example, a CMarkup object is instantiated and with one call to FindSetData, multiple levels of elements are created.

CMarkup xml;
xml.FindSetData("/Configuration/Dir", "C:\\Temp" );
<Configuration>
<Dir>C:\Temp</Dir>
</Configuration>

One more call adds more elements (indentation added for illustration):

FindSetData("/*/WindowPos/Right", "400" );
<Configuration>
  <Dir>C:\Temp</Dir>
  <WindowPos>
    <Right>400</Right>
  </WindowPos>
</Configuration>

As with SetData, the MNF_WITHCDATA and MNF_WITHREFS flags can be used to affect how the data content is stored.