int TiXmlElement::Printe( char * xmlstr, int totallen, int depth, int& len ) { char tempstr[MAX_XML_SIZE] = {0}; int i; for ( i=0; i<depth; i++ ) { sprintf( tempstr, " " ); SAFE_STRCAT; } sprintf( tempstr, "<%s", value.c_str() ); SAFE_STRCAT; TiXmlAttribute* attrib; for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() ) { sprintf( tempstr, " " ); SAFE_STRCAT; if ( attrib->Printe( xmlstr, totallen, depth, len ) < 0 ) { return -2; } } // 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. TiXmlNode* node; if ( !firstChild ) { sprintf( tempstr, " />" ); SAFE_STRCAT; } else if ( firstChild == lastChild && firstChild->ToText() ) { sprintf( tempstr, ">" ); SAFE_STRCAT; if ( firstChild->Printe( xmlstr, totallen, depth + 1, len ) < 0 ) { return -2; } sprintf( tempstr, "</%s>", value.c_str() ); SAFE_STRCAT; } else { sprintf( tempstr, ">" ); SAFE_STRCAT; for ( node = firstChild; node; node = node->NextSibling() ) { if ( !node->ToText() ) { sprintf( tempstr, "\n" ); SAFE_STRCAT; } if ( node->Printe( xmlstr, totallen, depth + 1, len ) < 0 ) { return -2; } } sprintf( tempstr, "\n" ); SAFE_STRCAT; for( i=0; i<depth; ++i ) { sprintf( tempstr, " " ); SAFE_STRCAT; } sprintf( tempstr, "</%s>", value.c_str() ); SAFE_STRCAT; } return 0; }
void TiXmlElement::Printe( char * xmlstr, int depth ) { char tempstr[MAX_XML_SIZE] = {0}; int i; for ( i=0; i<depth; i++ ) { sprintf( tempstr, " " ); strcat(xmlstr, tempstr); //printf("String = %s, string len = %d\n", tempstr, strlen(tempstr)); } sprintf( tempstr, "<%s", value.c_str() ); strcat(xmlstr, tempstr); //printf("String = %s, string len = %d\n", tempstr, strlen(tempstr)); TiXmlAttribute* attrib; for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() ) { sprintf( tempstr, " " ); strcat(xmlstr, tempstr); //printf("String = %s, string len = %d\n", tempstr, strlen(tempstr)); attrib->Printe( xmlstr, 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. TiXmlNode* node; if ( !firstChild ) { sprintf( tempstr, " />" ); strcat(xmlstr, tempstr); //printf("String = %s, string len = %d\n", tempstr, strlen(tempstr)); } else if ( firstChild == lastChild && firstChild->ToText() ) { sprintf( tempstr, ">" ); strcat(xmlstr, tempstr); //printf("String = %s, string len = %d\n", tempstr, strlen(tempstr)); firstChild->Printe( xmlstr, depth + 1 ); sprintf( tempstr, "</%s>", value.c_str() ); strcat(xmlstr, tempstr); //printf("String = %s, string len = %d\n", tempstr, strlen(tempstr)); } else { sprintf( tempstr, ">" ); strcat(xmlstr, tempstr); //printf("String = %s, string len = %d\n", tempstr, strlen(tempstr)); for ( node = firstChild; node; node = node->NextSibling() ) { if ( !node->ToText() ) { sprintf( tempstr, "\n" ); strcat(xmlstr, tempstr); //printf("String = %s, string len = %d\n", tempstr, strlen(tempstr)); } node->Printe( xmlstr, depth + 1 ); } sprintf( tempstr, "\n" ); strcat(xmlstr, tempstr); //printf("String = %s, string len = %d\n", tempstr, strlen(tempstr)); for( i=0; i<depth; ++i ) { sprintf( tempstr, " " ); strcat(xmlstr, tempstr); //printf("String = %s, string len = %d\n", tempstr, strlen(tempstr)); } sprintf( tempstr, "</%s>", value.c_str() ); strcat(xmlstr, tempstr); //printf("String = %s, string len = %d\n", tempstr, strlen(tempstr)); } }