本文整理汇总了C++中XMLNode::ParseXMLElement方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLNode::ParseXMLElement方法的具体用法?C++ XMLNode::ParseXMLElement怎么用?C++ XMLNode::ParseXMLElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLNode
的用法示例。
在下文中一共展示了XMLNode::ParseXMLElement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
/**
* Recursively parse an XML element.
*/
bool
XMLNode::ParseXMLElement(XML *pXML)
{
const TCHAR *lpszTemp = NULL;
size_t cbTemp;
unsigned nDeclaration;
const TCHAR *lpszText = NULL;
XMLNode pNew;
enum Status status; // inside or outside a tag
enum Attrib attrib = eAttribName;
assert(pXML);
// If this is the first call to the function
if (pXML->nFirst) {
// Assume we are outside of a tag definition
pXML->nFirst = false;
status = eOutsideTag;
} else {
// If this is not the first call then we should only be called when inside a tag.
status = eInsideTag;
}
// Iterate through the tokens in the document
while (true) {
// Obtain the next token
size_t cbToken;
enum TokenTypeTag type;
NextToken token = GetNextToken(pXML, &cbToken, &type);
if (gcc_unlikely(type == eTokenError))
return false;
// Check the current status
switch (status) {
// If we are outside of a tag definition
case eOutsideTag:
// Check what type of token we obtained
switch (type) {
// If we have found text or quoted text
case eTokenText:
case eTokenQuotedText:
case eTokenEquals:
if (!lpszText)
lpszText = token.pStr;
break;
// If we found a start tag '<' and declarations '<?'
case eTokenTagStart:
case eTokenDeclaration:
// Cache whether this new element is a declaration or not
nDeclaration = type == eTokenDeclaration;
// If we have node text then add this to the element
if (lpszText) {
cbTemp = token.pStr - lpszText;
FindEndOfText(lpszText, &cbTemp);
AddText(lpszText, cbTemp);
lpszText = NULL;
}
// Find the name of the tag
token = GetNextToken(pXML, &cbToken, &type);
// Return an error if we couldn't obtain the next token or
// it wasnt text
if (type != eTokenText) {
pXML->error = eXMLErrorMissingTagName;
return false;
}
// If we found a new element which is the same as this
// element then we need to pass this back to the caller..
#ifdef APPROXIMATE_PARSING
if (d->lpszName && myTagCompare(d->lpszName, token.pStr)) {
// Indicate to the caller that it needs to create a
// new element.
pXML->lpNewElement = token.pStr;
pXML->cbNewElement = cbToken;
return true;
}
#endif
// If the name of the new element differs from the name of
// the current element we need to add the new element to
// the current one and recurse
pNew = AddChild(stringDup(token.pStr, cbToken), nDeclaration);
while (true) {
// Callself to process the new node. If we return
// FALSE this means we dont have any more
// processing to do...
if (!pNew.ParseXMLElement(pXML)) {
return false;
//.........这里部分代码省略.........