| 783 | |
| 784 | |
| 785 | char* XMLNode::ParseDeep( char* p, StrPair* parentEnd ) |
| 786 | { |
| 787 | // This is a recursive method, but thinking about it "at the current level" |
| 788 | // it is a pretty simple flat list: |
| 789 | // <foo/> |
| 790 | // <!-- comment --> |
| 791 | // |
| 792 | // With a special case: |
| 793 | // <foo> |
| 794 | // </foo> |
| 795 | // <!-- comment --> |
| 796 | // |
| 797 | // Where the closing element (/foo) *must* be the next thing after the opening |
| 798 | // element, and the names must match. BUT the tricky bit is that the closing |
| 799 | // element will be read by the child. |
| 800 | // |
| 801 | // 'endTag' is the end tag for this node, it is returned by a call to a child. |
| 802 | // 'parentEnd' is the end tag for the parent, which is filled in and returned. |
| 803 | |
| 804 | while( p && *p ) { |
| 805 | XMLNode* node = 0; |
| 806 | |
| 807 | p = _document->Identify( p, &node ); |
| 808 | if ( p == 0 || node == 0 ) { |
| 809 | break; |
| 810 | } |
| 811 | |
| 812 | StrPair endTag; |
| 813 | p = node->ParseDeep( p, &endTag ); |
| 814 | if ( !p ) { |
| 815 | DeleteNode( node ); |
| 816 | node = 0; |
| 817 | if ( !_document->Error() ) { |
| 818 | _document->SetError( XML_ERROR_PARSING, 0, 0 ); |
| 819 | } |
| 820 | break; |
| 821 | } |
| 822 | |
| 823 | XMLElement* ele = node->ToElement(); |
| 824 | // We read the end tag. Return it to the parent. |
| 825 | if ( ele && ele->ClosingType() == XMLElement::CLOSING ) { |
| 826 | if ( parentEnd ) { |
| 827 | *parentEnd = ele->_value; |
| 828 | } |
| 829 | node->_memPool->SetTracked(); // created and then immediately deleted. |
| 830 | DeleteNode( node ); |
| 831 | return p; |
| 832 | } |
| 833 | |
| 834 | // Handle an end tag returned to this level. |
| 835 | // And handle a bunch of annoying errors. |
| 836 | if ( ele ) { |
| 837 | bool mismatch = false; |
| 838 | if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) { |
| 839 | mismatch = true; |
| 840 | } |
| 841 | else if ( !endTag.Empty() && ele->ClosingType() != XMLElement::OPEN ) { |
| 842 | mismatch = true; |
no test coverage detected