| 771 | |
| 772 | |
| 773 | void TiXmlElement::Print( FILE* cfile, int depth ) const |
| 774 | { |
| 775 | int i; |
| 776 | assert( cfile ); |
| 777 | for ( i=0; i<depth; i++ ) { |
| 778 | fprintf( cfile, " " ); |
| 779 | } |
| 780 | |
| 781 | fprintf( cfile, "<%s", value.c_str() ); |
| 782 | |
| 783 | const TiXmlAttribute* attrib; |
| 784 | for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() ) |
| 785 | { |
| 786 | fprintf( cfile, " " ); |
| 787 | attrib->Print( cfile, depth ); |
| 788 | } |
| 789 | |
| 790 | // There are 3 different formatting approaches: |
| 791 | // 1) An element without children is printed as a <foo /> node |
| 792 | // 2) An element with only a text child is printed as <foo> text </foo> |
| 793 | // 3) An element with children is printed on multiple lines. |
| 794 | TiXmlNode* node; |
| 795 | if ( !firstChild ) |
| 796 | { |
| 797 | fprintf( cfile, " />" ); |
| 798 | } |
| 799 | else if ( firstChild == lastChild && firstChild->ToText() ) |
| 800 | { |
| 801 | fprintf( cfile, ">" ); |
| 802 | firstChild->Print( cfile, depth + 1 ); |
| 803 | fprintf( cfile, "</%s>", value.c_str() ); |
| 804 | } |
| 805 | else |
| 806 | { |
| 807 | fprintf( cfile, ">" ); |
| 808 | |
| 809 | for ( node = firstChild; node; node=node->NextSibling() ) |
| 810 | { |
| 811 | if ( !node->ToText() ) |
| 812 | { |
| 813 | fprintf( cfile, "\n" ); |
| 814 | } |
| 815 | node->Print( cfile, depth+1 ); |
| 816 | } |
| 817 | fprintf( cfile, "\n" ); |
| 818 | for( i=0; i<depth; ++i ) { |
| 819 | fprintf( cfile, " " ); |
| 820 | } |
| 821 | fprintf( cfile, "</%s>", value.c_str() ); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | |
| 826 | void TiXmlElement::CopyTo( TiXmlElement* target ) const |