| 986 | |
| 987 | |
| 988 | char* XMLNode::ParseDeep(char* p, StrPair* parentEndTag, int* curLineNumPtr) |
| 989 | { |
| 990 | // This is a recursive method, but thinking about it "at the current level" |
| 991 | // it is a pretty simple flat list: |
| 992 | // <foo/> |
| 993 | // <!-- comment --> |
| 994 | // |
| 995 | // With a special case: |
| 996 | // <foo> |
| 997 | // </foo> |
| 998 | // <!-- comment --> |
| 999 | // |
| 1000 | // Where the closing element (/foo) *must* be the next thing after the opening |
| 1001 | // element, and the names must match. BUT the tricky bit is that the closing |
| 1002 | // element will be read by the child. |
| 1003 | // |
| 1004 | // 'endTag' is the end tag for this node, it is returned by a call to a child. |
| 1005 | // 'parentEnd' is the end tag for the parent, which is filled in and returned. |
| 1006 | |
| 1007 | while (p && *p) { |
| 1008 | XMLNode* node = 0; |
| 1009 | |
| 1010 | p = _document->Identify(p, &node); |
| 1011 | TIXMLASSERT(p); |
| 1012 | if (node == 0) { |
| 1013 | break; |
| 1014 | } |
| 1015 | |
| 1016 | int initialLineNum = node->_parseLineNum; |
| 1017 | |
| 1018 | StrPair endTag; |
| 1019 | p = node->ParseDeep(p, &endTag, curLineNumPtr); |
| 1020 | if (!p) { |
| 1021 | DeleteNode(node); |
| 1022 | if (!_document->Error()) { |
| 1023 | _document->SetError(XML_ERROR_PARSING, 0, 0, initialLineNum); |
| 1024 | } |
| 1025 | break; |
| 1026 | } |
| 1027 | |
| 1028 | XMLDeclaration* decl = node->ToDeclaration(); |
| 1029 | if (decl) { |
| 1030 | // Declarations are only allowed at document level |
| 1031 | bool wellLocated = (ToDocument() != 0); |
| 1032 | if (wellLocated) { |
| 1033 | // Multiple declarations are allowed but all declarations |
| 1034 | // must occur before anything else |
| 1035 | for (const XMLNode* existingNode = _document->FirstChild(); existingNode; existingNode = existingNode->NextSibling()) { |
| 1036 | if (!existingNode->ToDeclaration()) { |
| 1037 | wellLocated = false; |
| 1038 | break; |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | if (!wellLocated) { |
| 1043 | _document->SetError(XML_ERROR_PARSING_DECLARATION, decl->Value(), 0, initialLineNum); |
| 1044 | DeleteNode(node); |
| 1045 | break; |
no test coverage detected