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