| 1044 | } |
| 1045 | |
| 1046 | char* XMLNode::ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr) |
| 1047 | { |
| 1048 | // This is a recursive method, but thinking about it "at the current level" |
| 1049 | // it is a pretty simple flat list: |
| 1050 | // <foo/> |
| 1051 | // <!-- comment --> |
| 1052 | // |
| 1053 | // With a special case: |
| 1054 | // <foo> |
| 1055 | // </foo> |
| 1056 | // <!-- comment --> |
| 1057 | // |
| 1058 | // Where the closing element (/foo) *must* be the next thing after the opening |
| 1059 | // element, and the names must match. BUT the tricky bit is that the closing |
| 1060 | // element will be read by the child. |
| 1061 | // |
| 1062 | // 'endTag' is the end tag for this node, it is returned by a call to a child. |
| 1063 | // 'parentEnd' is the end tag for the parent, which is filled in and returned. |
| 1064 | |
| 1065 | XMLDocument::DepthTracker tracker(_document); |
| 1066 | if (_document->Error()) |
| 1067 | return 0; |
| 1068 | |
| 1069 | while (p && *p) |
| 1070 | { |
| 1071 | XMLNode* node = 0; |
| 1072 | |
| 1073 | p = _document->Identify(p, &node); |
| 1074 | TIXMLASSERT(p); |
| 1075 | if (node == 0) |
| 1076 | { |
| 1077 | break; |
| 1078 | } |
| 1079 | |
| 1080 | int initialLineNum = node->_parseLineNum; |
| 1081 | |
| 1082 | StrPair endTag; |
| 1083 | p = node->ParseDeep(p, &endTag, curLineNumPtr); |
| 1084 | if (!p) |
| 1085 | { |
| 1086 | DeleteNode(node); |
| 1087 | if (!_document->Error()) |
| 1088 | { |
| 1089 | _document->SetError(XML_ERROR_PARSING, initialLineNum, 0); |
| 1090 | } |
| 1091 | break; |
| 1092 | } |
| 1093 | |
| 1094 | XMLDeclaration* decl = node->ToDeclaration(); |
| 1095 | if (decl) |
| 1096 | { |
| 1097 | // Declarations are only allowed at document level |
| 1098 | bool wellLocated = (ToDocument() != 0); |
| 1099 | if (wellLocated) |
| 1100 | { |
| 1101 | // Multiple declarations are allowed but all declarations |
| 1102 | // must occur before anything else |
| 1103 | for (const XMLNode* existingNode = _document->FirstChild(); existingNode; existingNode = existingNode->NextSibling()) |
no test coverage detected