当前位置: 首页>>代码示例>>C++>>正文


C++ XMLNode::ParseXMLElement方法代码示例

本文整理汇总了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;
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的XMLNode::ParseXMLElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。