| 557 | } |
| 558 | |
| 559 | void TiXmlElement::Print( FILE* cfile, int depth ) const |
| 560 | { |
| 561 | int i; |
| 562 | for ( i=0; i<depth; i++ ) |
| 563 | { |
| 564 | generic_fprintf( cfile, TEXT(" ") ); |
| 565 | } |
| 566 | |
| 567 | generic_fprintf( cfile, TEXT("<%s"), value.c_str() ); |
| 568 | |
| 569 | TiXmlAttribute* attrib; |
| 570 | for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() ) |
| 571 | { |
| 572 | generic_fprintf( cfile, TEXT(" ") ); |
| 573 | attrib->Print( cfile, depth ); |
| 574 | } |
| 575 | |
| 576 | // There are 3 different formatting approaches: |
| 577 | // 1) An element without children is printed as a <foo /> node |
| 578 | // 2) An element with only a text child is printed as <foo> text </foo> |
| 579 | // 3) An element with children is printed on multiple lines. |
| 580 | TiXmlNode* node; |
| 581 | if ( !firstChild ) |
| 582 | { |
| 583 | generic_fprintf( cfile, TEXT(" />") ); |
| 584 | } |
| 585 | else if ( firstChild == lastChild && firstChild->ToText() ) |
| 586 | { |
| 587 | generic_fprintf( cfile, TEXT(">") ); |
| 588 | firstChild->Print( cfile, depth + 1 ); |
| 589 | generic_fprintf( cfile, TEXT("</%s>"), value.c_str() ); |
| 590 | } |
| 591 | else |
| 592 | { |
| 593 | generic_fprintf( cfile, TEXT(">") ); |
| 594 | |
| 595 | for ( node = firstChild; node; node=node->NextSibling() ) |
| 596 | { |
| 597 | if ( !node->ToText() ) |
| 598 | { |
| 599 | generic_fprintf( cfile, TEXT("\n") ); |
| 600 | } |
| 601 | node->Print( cfile, depth+1 ); |
| 602 | } |
| 603 | generic_fprintf( cfile, TEXT("\n") ); |
| 604 | for( i=0; i<depth; ++i ) |
| 605 | generic_fprintf( cfile, TEXT(" ") ); |
| 606 | generic_fprintf( cfile, TEXT("</%s>"), value.c_str() ); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | void TiXmlElement::StreamOut( TIXML_OSTREAM * stream ) const |
| 611 | { |