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