# Document Tree

## Functions
TidyNode | tidyGetRoot (TidyDoc tdoc)
TidyNode | tidyGetHtml (TidyDoc tdoc)
TidyNode | tidyGetHead (TidyDoc tdoc)
TidyNode | tidyGetBody (TidyDoc tdoc)
TidyNode | tidyGetParent (TidyNode tnod)
TidyNode | tidyGetChild (TidyNode tnod)
TidyNode | tidyGetNext (TidyNode tnod)
TidyNode | tidyGetPrev (TidyNode tnod)
TidyAttr | tidyAttrFirst (TidyNode tnod)
TidyAttr | tidyAttrNext (TidyAttr tattr)
ctmbstr | tidyAttrName (TidyAttr tattr)
ctmbstr | tidyAttrValue (TidyAttr tattr)

## Detailed Description

A parsed and, optionally, repaired document is represented by Tidy as a Tree, much like a W3C DOM. This tree may be traversed using these functions. The following snippet gives a basic idea how these functions can be used.

    void dumpNode( TidyNode tnod, int indent )
    {
      TidyNode child;

      for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) )
      {
        ctmbstr name = tidyNodeGetName( child );
        if ( !name )
        {
          switch ( tidyNodeGetType(child) )
          {
          case TidyNode_Root:       name = "Root";                    break;
          case TidyNode_DocType:    name = "DOCTYPE";                 break;
          case TidyNode_Comment:    name = "Comment";                 break;
          case TidyNode_ProcIns:    name = "Processing Instruction";  break;
          case TidyNode_Text:       name = "Text";                    break;
          case TidyNode_CDATA:      name = "CDATA";                   break;
          case TidyNode_Section:    name = "XML Section";             break;
          case TidyNode_Asp:        name = "ASP";                     break;
          case TidyNode_Jste:       name = "JSTE";                    break;
          case TidyNode_Php:        name = "PHP";                     break;
          case TidyNode_XmlDecl:    name = "XML Declaration";         break;

          case TidyNode_Start:
          case TidyNode_End:
          case TidyNode_StartEnd:
          default:
            assert( name != NULL ); // Shouldn't get here
            break;
          }
        }
        assert( name != NULL );
        printf( "%*.*sNode: %s\n", indent, indent, tidy );
        dumpNode( child, indent + 4 );
      }
    }

    void dumpDoc( TidyDoc tdoc )
    {
      dumpNode( tidyGetRoot(tdoc), 0 );
    }

    void dumpBody( TidyDoc tdoc )
    {
      dumpNode( tidyGetBody(tdoc), 0 );
    }