| 639 | #ifdef TIXML_USE_STL |
| 640 | |
| 641 | void TiXmlDocument::StreamIn( std::istream * in, TIXML_STRING * tag ) |
| 642 | { |
| 643 | // The basic issue with a document is that we don't know what we're |
| 644 | // streaming. Read something presumed to be a tag (and hope), then |
| 645 | // identify it, and call the appropriate stream method on the tag. |
| 646 | // |
| 647 | // This "pre-streaming" will never read the closing ">" so the |
| 648 | // sub-tag can orient itself. |
| 649 | |
| 650 | if ( !StreamTo( in, '<', tag ) ) |
| 651 | { |
| 652 | SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); |
| 653 | return; |
| 654 | } |
| 655 | |
| 656 | while ( in->good() ) |
| 657 | { |
| 658 | int tagIndex = (int) tag->length(); |
| 659 | while ( in->good() && in->peek() != '>' ) |
| 660 | { |
| 661 | int c = in->get(); |
| 662 | if ( c <= 0 ) |
| 663 | { |
| 664 | SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); |
| 665 | break; |
| 666 | } |
| 667 | (*tag) += (char) c; |
| 668 | } |
| 669 | |
| 670 | if ( in->good() ) |
| 671 | { |
| 672 | // We now have something we presume to be a node of |
| 673 | // some sort. Identify it, and call the node to |
| 674 | // continue streaming. |
| 675 | TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING ); |
| 676 | |
| 677 | if ( node ) |
| 678 | { |
| 679 | node->StreamIn( in, tag ); |
| 680 | bool isElement = node->ToElement() != 0; |
| 681 | delete node; |
| 682 | node = 0; |
| 683 | |
| 684 | // If this is the root element, we're done. Parsing will be |
| 685 | // done by the >> operator. |
| 686 | if ( isElement ) |
| 687 | { |
| 688 | return; |
| 689 | } |
| 690 | } |
| 691 | else |
| 692 | { |
| 693 | SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); |
| 694 | return; |
| 695 | } |
| 696 | } |
| 697 | } |
| 698 | // We should have returned sooner. |