| 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 | XMLDocument::DepthTracker tracker(_document); |
| 1008 | if (_document->Error()) |
| 1009 | return 0; |
| 1010 | |
| 1011 | while( p && *p ) { |
| 1012 | XMLNode* node = 0; |
| 1013 | |
| 1014 | p = _document->Identify( p, &node ); |
| 1015 | TIXMLASSERT( p ); |
| 1016 | if ( node == 0 ) { |
| 1017 | break; |
| 1018 | } |
| 1019 | |
| 1020 | int initialLineNum = node->_parseLineNum; |
| 1021 | |
| 1022 | StrPair endTag; |
| 1023 | p = node->ParseDeep( p, &endTag, curLineNumPtr ); |
| 1024 | if ( !p ) { |
| 1025 | DeleteNode( node ); |
| 1026 | if ( !_document->Error() ) { |
| 1027 | _document->SetError( XML_ERROR_PARSING, initialLineNum, 0); |
| 1028 | } |
| 1029 | break; |
| 1030 | } |
| 1031 | |
| 1032 | XMLDeclaration* decl = node->ToDeclaration(); |
| 1033 | if ( decl ) { |
| 1034 | // Declarations are only allowed at document level |
| 1035 | bool wellLocated = ( ToDocument() != 0 ); |
| 1036 | if ( wellLocated ) { |
| 1037 | // Multiple declarations are allowed but all declarations |
| 1038 | // must occur before anything else |
| 1039 | for ( const XMLNode* existingNode = _document->FirstChild(); existingNode; existingNode = existingNode->NextSibling() ) { |
| 1040 | if ( !existingNode->ToDeclaration() ) { |
| 1041 | wellLocated = false; |
| 1042 | break; |
| 1043 | } |
| 1044 | } |
| 1045 | } |
no test coverage detected