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