Exemplo n.º 1
0
void TiXmlElement::toStream( std::ostream& stream, int depth ) const
{
	int i;
	for ( i=0; i<depth; i++ )
		stream << "    ";

	stream << "<" << value;

	const TiXmlAttribute* attrib;
	for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() )
	{
		stream << " ";
		attrib->toStream( stream, 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 )
	{
		stream << " />";
	}
	else if ( firstChild == lastChild && firstChild->ToText() )
	{
		stream << ">";
		firstChild->toStream( stream, depth + 1 );
		stream << "</" << value << ">";
	}
	else
	{
		stream << ">";

		for ( node = firstChild; node; node=node->NextSibling() )
		{
			if ( !node->ToText() )
			{
				stream << "\n";
			}
			node->toStream( stream, depth+1 );
		}
		stream << "\n";
		for( i=0; i<depth; ++i )
			stream << "    ";
		stream << "</" << value << ">";
	}
}