/// <summary> /// Print this Document to a FILE stream. /// </summary> public override void Print(StringBuilder cfile, int depth) { //assert( cfile ); for (TiXmlNode node = FirstChild(); node != null; node = node.NextSibling()) { node.Print(cfile, depth); //fprintf(cfile, "\n"); cfile.Append("\n"); } }
/// <summary> /// Print the Element to a FILE stream. /// </summary> public override void Print(StringBuilder cfile, int depth) { //assert( cfile ); for (int i = 0; i < depth; i++) { //fprintf( cfile, " " ); cfile.Append(" "); } cfile.Append("<"); cfile.Append(value); //fprintf( cfile, "<%s", value.c_str() ); for (TiXmlAttribute attrib = attributeSet.First(); attrib != null; attrib = attrib.Next()) { cfile.Append(" "); //fprintf(cfile, " "); attrib.Print(cfile, depth); } // There are 3 different formatting approaches: // 1) An element without children is printed as a <foo /> node // 2) An element with only a text child is printed as <foo> text </foo> // 3) An element with children is printed on multiple lines. if (firstChild == null) { //fprintf(cfile, " />"); cfile.Append(" />"); } else if (firstChild == lastChild && firstChild.ToText() != null) { //fprintf(cfile, ">"); cfile.Append(">"); firstChild.Print(cfile, depth + 1); //fprintf(cfile, "</%s>", value.c_str()); cfile.Append("</"); cfile.Append(value); cfile.Append(">"); } else { //fprintf(cfile, ">"); cfile.Append(">"); for (TiXmlNode node = firstChild; node != null; node = node.NextSibling()) { if (node.ToText() == null) { //fprintf(cfile, "\n"); cfile.Append("\n"); } node.Print(cfile, depth + 1); } //fprintf(cfile, "\n"); cfile.Append("\n"); for (int i = 0; i < depth; ++i) { //fprintf(cfile, " "); cfile.Append(" "); } //fprintf(cfile, "</%s>", value.c_str()); cfile.Append("</"); cfile.Append(value); cfile.Append(">"); } }