| 716 | #endif |
| 717 | |
| 718 | void TiXmlElement::Print(FILE* cfile, int depth) const |
| 719 | { |
| 720 | int i; |
| 721 | assert(cfile); |
| 722 | for (i = 0; i < depth; i++) |
| 723 | { |
| 724 | fprintf(cfile, " "); |
| 725 | } |
| 726 | |
| 727 | fprintf(cfile, "<%s", value.c_str()); |
| 728 | |
| 729 | const TiXmlAttribute* attrib; |
| 730 | for (attrib = attributeSet.First(); attrib; attrib = attrib->Next()) |
| 731 | { |
| 732 | fprintf(cfile, " "); |
| 733 | attrib->Print(cfile, depth); |
| 734 | } |
| 735 | |
| 736 | // There are 3 different formatting approaches: |
| 737 | // 1) An element without children is printed as a <foo /> node |
| 738 | // 2) An element with only a text child is printed as <foo> text </foo> |
| 739 | // 3) An element with children is printed on multiple lines. |
| 740 | TiXmlNode* node; |
| 741 | if (!firstChild) |
| 742 | { |
| 743 | fprintf(cfile, " />"); |
| 744 | } |
| 745 | else if (firstChild == lastChild && firstChild->ToText()) |
| 746 | { |
| 747 | fprintf(cfile, ">"); |
| 748 | firstChild->Print(cfile, depth + 1); |
| 749 | fprintf(cfile, "</%s>", value.c_str()); |
| 750 | } |
| 751 | else |
| 752 | { |
| 753 | fprintf(cfile, ">"); |
| 754 | |
| 755 | for (node = firstChild; node; node = node->NextSibling()) |
| 756 | { |
| 757 | if (!node->ToText()) |
| 758 | { |
| 759 | fprintf(cfile, "\n"); |
| 760 | } |
| 761 | node->Print(cfile, depth + 1); |
| 762 | } |
| 763 | fprintf(cfile, "\n"); |
| 764 | for (i = 0; i < depth; ++i) |
| 765 | { |
| 766 | fprintf(cfile, " "); |
| 767 | } |
| 768 | fprintf(cfile, "</%s>", value.c_str()); |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | void TiXmlElement::CopyTo(TiXmlElement* target) const |
| 773 | { |