Logo Search packages:      
Sourcecode: passwordmaker-cli version File versions  Download package

void TiXmlElement::Print ( FILE *  cfile,
int  depth 
) const [virtual]

All TinyXml classes can print themselves to a filestream. This is a formatted print, and will insert tabs and newlines.

(For an unformatted stream, use the << operator.)

Implements TiXmlBase.

Definition at line 767 of file tinyxml.cpp.

References TiXmlAttribute::Next(), TiXmlNode::NextSibling(), TiXmlBase::Print(), and TiXmlNode::ToText().

{
      int i;
      for ( i=0; i<depth; i++ )
      {
            fprintf( cfile, "    " );
      }

      fprintf( cfile, "<%s", value.c_str() );

      const TiXmlAttribute* attrib;
      for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() )
      {
            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.
      TiXmlNode* node;
      if ( !firstChild )
      {
            fprintf( cfile, " />" );
      }
      else if ( firstChild == lastChild && firstChild->ToText() )
      {
            fprintf( cfile, ">" );
            firstChild->Print( cfile, depth + 1 );
            fprintf( cfile, "</%s>", value.c_str() );
      }
      else
      {
            fprintf( cfile, ">" );

            for ( node = firstChild; node; node=node->NextSibling() )
            {
                  if ( !node->ToText() )
                  {
                        fprintf( cfile, "\n" );
                  }
                  node->Print( cfile, depth+1 );
            }
            fprintf( cfile, "\n" );
            for( i=0; i<depth; ++i )
            fprintf( cfile, "    " );
            fprintf( cfile, "</%s>", value.c_str() );
      }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index