<a>
   <b>
</a>类似这么一棵树,LOAD完以后如何获得根元素的值(a)

解决方案 »

  1.   

    CMarkup FindElem Methodbool CMarkup::FindElem( MCD_CSTR szName = NULL );The FindElem should be thought of as "FindNextElem" because it goes forward from the current main position to the next matching sibling element. If there is no next sibling element it returns false and leaves the main position where it was.In the following example, if there is no current position (when the document is loaded or after calling ResetPos), calling FindElem() will set the main position to the TESTDOC element. Calling FindElem() a second time will return false and leave the current main position at the TESTDOC element.<TESTDOC>
    <ITEM>one</ITEM>
    <ITEM>two</ITEM>
    </TESTDOC>xml.ResetPos();
    xml.FindElem(); // succeeds, at TESTDOC
    xml.FindElem(); // fails, stays at TESTDOCGoing into TESTDOC, the first call to FindElem() sets the main position to the first ITEM element. If the main position is at the first ITEM element then calling FindElem() will set the main position to the second ITEM element.xml.IntoElem(); // inside TESTDOC
    xml.FindElem(); // first ITEM
    xml.FindElem(); // second ITEMHaving no main position is like being before the first child of the current parent position. This means that the first call to FindElem() will go to the first child of the parent position element. The ResetMainPos method clears the main position.The FindElem method has an optional argument which allows you to specify a tag name or path. The simplest use of this argument is to pass the tag name. Calling FindElem("ITEM") will only succeed if a sibling ITEM element is found after the main position under the current parent position. If there is no main position, it will look for the first ITEM element under the current parent.If the main position is at the first ITEM element in the above example, then calling FindElem("ITEM") will set the main position to the second ITEM element. Since there is no THING element, calling FindElem("THING") would not affect the main position and return false.