Index: doxia-core/src/main/java/org/apache/maven/doxia/sink/SinkUtils.java
===================================================================
--- doxia-core/src/main/java/org/apache/maven/doxia/sink/SinkUtils.java	(revision 694218)
+++ doxia-core/src/main/java/org/apache/maven/doxia/sink/SinkUtils.java	(working copy)
@@ -214,7 +214,7 @@
         return sb.toString();
     }
 
-    private static String asCssString( AttributeSet att )
+    public static String asCssString( AttributeSet att )
     {
         StringBuffer sb = new StringBuffer();
 
Index: doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java
===================================================================
--- doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java	(revision 694218)
+++ doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java	(working copy)
@@ -21,7 +21,10 @@
 
 import java.io.PrintWriter;
 import java.io.Writer;
+import java.util.Enumeration;
+import java.util.LinkedList;
 
+import javax.swing.text.AttributeSet;
 import javax.swing.text.MutableAttributeSet;
 import javax.swing.text.html.HTML.Attribute;
 import javax.swing.text.html.HTML.Tag;
@@ -29,9 +32,11 @@
 import org.apache.maven.doxia.markup.HtmlMarkup;
 import org.apache.maven.doxia.util.DoxiaUtils;
 import org.apache.maven.doxia.util.HtmlTools;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 
 /**
- * Abstract base xhtml sink implementation.
+ * Abstract base xhtml sink implementation. This implementation uses {@link PrettyPrintXMLWriter}.
  *
  * @author Jason van Zyl
  * @author ltheussl
@@ -47,8 +52,11 @@
     // ----------------------------------------------------------------------
 
     /** The PrintWriter to write the result. */
-    private PrintWriter writer;
+    private PrintWriter out;
 
+    /** The XMLWriter to write nicely the result. */
+    private DoxiaPrettyPrintXMLWriter writer;
+
     /** Used to collect text events. */
     private StringBuffer buffer = new StringBuffer();
 
@@ -93,7 +101,8 @@
      */
     public XhtmlBaseSink( Writer out )
     {
-        this.writer = new PrintWriter( out );
+        this.out = new PrintWriter( out );
+        this.writer = new DoxiaPrettyPrintXMLWriter( out );
     }
 
     // ----------------------------------------------------------------------
@@ -1359,7 +1368,7 @@
             att.addAttribute( Attribute.CLASS, "externalLink" );
         }
 
-        att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( href  ) );
+        att.addAttribute( Attribute.HREF, href );
 
         if ( target != null )
         {
@@ -1648,13 +1657,13 @@
     /** {@inheritDoc} */
     public void flush()
     {
-        writer.flush();
+        out.flush();
     }
 
     /** {@inheritDoc} */
     public void close()
     {
-        writer.close();
+        IOUtil.close( out );
     }
 
     // ----------------------------------------------------------------------
@@ -1709,7 +1718,104 @@
     /** {@inheritDoc} */
     protected void write( String text )
     {
-        writer.write( unifyEOLs( text ) );
+        write( text, false );
     }
 
+    protected void write( String text, boolean escapeXml )
+    {
+        if ( escapeXml )
+        {
+            writer.writeText( unifyEOLs( text ) );
+        }
+        else
+        {
+            writer.writeMarkup( unifyEOLs( text ) );
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void writeStartTag( Tag t, MutableAttributeSet att, boolean isSimpleTag )
+    {
+        if ( t == null )
+        {
+            throw new IllegalArgumentException( "A tag is required" );
+        }
+
+        if ( getNameSpace() != null )
+        {
+            writer.startElement( getNameSpace() + ":" + t.toString() );
+        }
+        else
+        {
+            writer.startElement( t.toString() );
+        }
+
+        if ( att != null )
+        {
+            Enumeration names = att.getAttributeNames();
+            while ( names.hasMoreElements() )
+            {
+                Object key = names.nextElement();
+                Object value = att.getAttribute( key );
+
+                if ( value instanceof AttributeSet )
+                {
+                    // Other AttributeSets are ignored
+                    if ( SinkEventAttributeSet.STYLE.equals( key.toString() ) )
+                    {
+                        writer.addAttribute( key.toString(), SinkUtils.asCssString( (AttributeSet) value ) );
+                    }
+                }
+                else
+                {
+                    writer.addAttribute( key.toString(), value.toString() );
+                }
+            }
+        }
+
+        if ( isSimpleTag )
+        {
+            writeEndTag( t );
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void writeEndTag( Tag t )
+    {
+        try
+        {
+            LinkedList elementStack = writer.getElementStack();
+            if ( elementStack.size() > 0 )
+            {
+                String last = (String) elementStack.getLast();
+                if ( last.equals( t.toString() ) )
+                {
+                    writer.endElement();
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Doxia implementation of {@link PrettyPrintXMLWriter}, mainly to allow getElementStack()
+     */
+    private static class DoxiaPrettyPrintXMLWriter
+        extends PrettyPrintXMLWriter
+    {
+
+        public DoxiaPrettyPrintXMLWriter( Writer writer )
+        {
+            super( writer );
+        }
+
+        /** {@inheritDoc} */
+        protected LinkedList getElementStack()
+        {
+            return super.getElementStack();
+        }
+    }
 }
Index: doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
===================================================================
--- doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java	(revision 696490)
+++ doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java	(working copy)
@@ -20,6 +20,7 @@
  */
 
 import java.io.Writer;
+import java.util.LinkedList;
 
 import javax.swing.text.MutableAttributeSet;
 import javax.swing.text.html.HTML.Attribute;
@@ -198,20 +199,44 @@
     {
         if ( depth == SECTION_LEVEL_1 )
         {
-            write( String.valueOf( LESS_THAN ) + SECTION_TAG.toString() + String.valueOf( SPACE ) + Attribute.NAME
-                + String.valueOf( EQUAL ) + String.valueOf( QUOTE )
-                + SinkUtils.getAttributeString( SinkUtils.filterAttributes(
-                    attributes, SinkUtils.SINK_BASE_ATTRIBUTES  ) ) );
+            this.internal.addLast( SECTION_TAG );
         }
         else if ( depth == SECTION_LEVEL_2 )
         {
-            write( String.valueOf( LESS_THAN ) + SUBSECTION_TAG.toString() + String.valueOf( SPACE ) + Attribute.NAME
-                + String.valueOf( EQUAL ) + String.valueOf( QUOTE )
-                + SinkUtils.getAttributeString( SinkUtils.filterAttributes(
-                    attributes, SinkUtils.SINK_BASE_ATTRIBUTES  ) ) );
+            this.internal.addLast( SUBSECTION_TAG );
         }
     }
 
+    LinkedList internal = new LinkedList();
+
+    public void write( String text )
+    {
+        if ( internal.size() == 0)
+        {
+            super.write( text );
+            return;
+        }
+
+        if ( internal.getLast().equals( SECTION_TAG ) )
+        {
+            internal.removeLast();
+            MutableAttributeSet att = new SinkEventAttributeSet();
+            att.addAttribute( Attribute.NAME, text );
+            writeStartTag( SECTION_TAG, att );
+        }
+        else if (  internal.getLast().equals( SUBSECTION_TAG ) )
+        {
+            internal.removeLast();
+            MutableAttributeSet att = new SinkEventAttributeSet();
+            att.addAttribute( Attribute.NAME, text );
+            writeStartTag( SUBSECTION_TAG, att);
+        }
+        else
+        {
+            super.write( text );
+        }
+    }
+
     /**
      * Ends a section.
      *
@@ -241,8 +266,7 @@
      */
     protected void onSectionTitle( int depth, SinkEventAttributes attributes )
     {
-        MutableAttributeSet atts = SinkUtils.filterAttributes(
-                attributes, SinkUtils.SINK_SECTION_ATTRIBUTES  );
+        MutableAttributeSet atts = SinkUtils.filterAttributes( attributes, SinkUtils.SINK_SECTION_ATTRIBUTES );
 
         if ( depth == SECTION_LEVEL_3 )
         {
@@ -270,7 +294,7 @@
     {
         if ( depth == SECTION_LEVEL_1 || depth == SECTION_LEVEL_2 )
         {
-            write( String.valueOf( QUOTE ) + String.valueOf( GREATER_THAN ) );
+            // nop
         }
         else if ( depth == SECTION_LEVEL_3 )
         {
@@ -299,10 +323,8 @@
     {
         setVerbatimFlag( true );
 
-        MutableAttributeSet atts = SinkUtils.filterAttributes(
-                attributes, SinkUtils.SINK_VERBATIM_ATTRIBUTES  );
+        MutableAttributeSet atts = SinkUtils.filterAttributes( attributes, SinkUtils.SINK_VERBATIM_ATTRIBUTES );
 
-
         if ( atts == null )
         {
             atts = new SinkEventAttributeSet();
@@ -312,8 +334,7 @@
 
         if ( atts.isDefined( SinkEventAttributes.DECORATION ) )
         {
-            boxed = "boxed".equals(
-                (String) atts.getAttribute( SinkEventAttributes.DECORATION ) );
+            boxed = "boxed".equals( (String) atts.getAttribute( SinkEventAttributes.DECORATION ) );
         }
 
         boxedFlag = boxed;
@@ -404,7 +425,7 @@
             att.addAttribute( Attribute.TARGET, target );
         }
 
-            att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( name ) );
+        att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( name ) );
 
         writeStartTag( Tag.A, att );
     }
Index: doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XmlWriterXdocSink.java
===================================================================
--- doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XmlWriterXdocSink.java	(revision 694218)
+++ doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XmlWriterXdocSink.java	(working copy)
@@ -31,7 +31,7 @@
  * @author juan <a href="mailto:james@jamestaylor.org">James Taylor</a>
  * @author Juan F. Codagnone  (replaced println with XmlWriterXdocSink)
  * @version $Id$
- * @component
+ * @deprecated Since 1.0, this class is no more maintained. Please use XdocSink which includes nicely printing.
  */
 public class XmlWriterXdocSink
     extends SinkAdapter
Index: doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
===================================================================
--- doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java	(revision 694218)
+++ doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java	(working copy)
@@ -237,7 +237,7 @@
     {
         return text.replaceAll( EOL, "" );
     }
-    
+
     public void testSectionIdAnchor()
         throws Exception
     {
@@ -250,10 +250,10 @@
         Iterator it = sink.getEventList().iterator();
 
         SinkEventElement anchorEvt = (SinkEventElement) it.next();
-        
+
         assertEquals( "anchor", anchorEvt.getName() );
         assertEquals( "test-id", anchorEvt.getArgs()[0] );
-        
+
         assertEquals( "anchor_", ( (SinkEventElement) it.next() ).getName() );
         assertEquals( "section1", ( (SinkEventElement) it.next() ).getName() );
         assertEquals( "sectionTitle1", ( (SinkEventElement) it.next() ).getName() );
Index: doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java
===================================================================
--- doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java	(revision 694218)
+++ doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java	(working copy)
@@ -66,13 +66,13 @@
     /** {@inheritDoc} */
     protected String getHeadBlock()
     {
-        return "<?xml version=\"1.0\" ?>" + EOL + "<document><properties></properties>";
+        return "<?xml version=\"1.0\" ?>" + EOL + "<document>" + EOL + "  <properties/>";
     }
 
     /** {@inheritDoc} */
     protected String getBodyBlock()
     {
-        return "<body></body></document>";
+        return "<body/>";
     }
 
     /** {@inheritDoc} */
@@ -84,13 +84,13 @@
     /** {@inheritDoc} */
     protected String getSection1Block( String title )
     {
-        return "<section name=\"" + title + "\"></section>";
+        return "<section name=\"" + title + "\"/>";
     }
 
     /** {@inheritDoc} */
     protected String getSection2Block( String title )
     {
-        return "<subsection name=\"" + title + "\"></subsection>";
+        return "<subsection name=\"" + title + "\"/>";
     }
 
     /** {@inheritDoc} */
@@ -114,19 +114,19 @@
     /** {@inheritDoc} */
     protected String getListBlock( String item )
     {
-        return "<ul><li>" + item + "</li></ul>";
+        return "<ul>" + EOL + "  <li>" + item + "</li>" + EOL + "</ul>";
     }
 
     /** {@inheritDoc} */
     protected String getNumberedListBlock( String item )
     {
-        return "<ol style=\"list-style-type: lower-roman\"><li>" + item + "</li></ol>";
+        return "<ol style=\"list-style-type: lower-roman\">" + EOL + "  <li>" + item + "</li>" + EOL + "</ol>";
     }
 
     /** {@inheritDoc} */
     protected String getDefinitionListBlock( String definum, String definition )
     {
-        return "<dl><dt>" + definum + "</dt><dd>" + definition + "</dd></dl>";
+        return "<dl>" + EOL + "  <dt>" + definum + "</dt>" + EOL + "  <dd>" + definition + "</dd>" + EOL + "</dl>";
     }
 
     /** {@inheritDoc} */
@@ -138,8 +138,8 @@
     /** {@inheritDoc} */
     protected String getTableBlock( String cell, String caption )
     {
-        return "<table align=\"center\" border=\"0\"><tr valign=\"top\"><td align=\"center\">"
-            + cell + "</td></tr><caption>" + caption + "</caption></table>";
+        return "<table align=\"center\" border=\"0\">" + EOL + "  <tr valign=\"top\">" + EOL + "    <td align=\"center\">"
+            + cell + "</td>" + EOL + "  </tr>" + EOL + "  <caption>" + caption + "</caption>" + EOL + "</table>";
     }
 
     /** {@inheritDoc} */
@@ -157,7 +157,7 @@
     /** {@inheritDoc} */
     protected String getHorizontalRuleBlock()
     {
-        return "<hr />";
+        return "<hr/>";
     }
 
     /** {@inheritDoc} */
@@ -199,7 +199,7 @@
     /** {@inheritDoc} */
     protected String getLineBreakBlock()
     {
-        return "<br />";
+        return "<br/>";
     }
 
     /** {@inheritDoc} */
Index: doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
===================================================================
--- doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java	(revision 694218)
+++ doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java	(working copy)
@@ -234,4 +234,8 @@
         isEmptyElement = false;
     }
 
+    protected boolean isIgnorableWhitespace()
+    {
+        return true;
+    }
 }
Index: doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
===================================================================
--- doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java	(revision 696490)
+++ doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java	(working copy)
@@ -50,7 +50,6 @@
     // TODO: this doesn't belong here
     private RenderingContext renderingContext;
 
-
     // ----------------------------------------------------------------------
     // Constructors
     // ----------------------------------------------------------------------
@@ -92,8 +91,10 @@
 
         setHeadFlag( true );
 
-        write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" );
-        write( "<html xmlns=\"http://www.w3.org/1999/xhtml\">" );
+        write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" + EOL );
+        MutableAttributeSet att = new SinkEventAttributeSet();
+        att.addAttribute( "xmlns", "http://www.w3.org/1999/xhtml" );
+        writeStartTag( Tag.HTML, att );
 
         writeStartTag( Tag.HEAD );
     }
Index: doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java
===================================================================
--- doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java	(revision 694218)
+++ doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java	(working copy)
@@ -81,13 +81,14 @@
     /** {@inheritDoc} */
     protected String getHeadBlock()
     {
-        return "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head>";
+        return "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
+            + EOL + "<html xmlns=\"http://www.w3.org/1999/xhtml\">" + EOL + "  <head/>";
     }
 
     /** {@inheritDoc} */
     protected String getBodyBlock()
     {
-        return "<body></body></html>";
+        return "<body/>";
     }
 
     /** {@inheritDoc} */
@@ -99,49 +100,49 @@
     /** {@inheritDoc} */
     protected String getSection1Block( String title )
     {
-        return "<div class=\"section\"><h2>" + title + "</h2></div>";
+        return "<div class=\"section\">" + EOL + "  <h2>" + title + "</h2>" + EOL + "</div>";
     }
 
     /** {@inheritDoc} */
     protected String getSection2Block( String title )
     {
-        return "<div class=\"section\"><h3>" + title + "</h3></div>";
+        return "<div class=\"section\">" + EOL + "  <h3>" + title + "</h3>" + EOL + "</div>";
     }
 
     /** {@inheritDoc} */
     protected String getSection3Block( String title )
     {
-        return "<div class=\"section\"><h4>" + title + "</h4></div>";
+        return "<div class=\"section\">" + EOL + "  <h4>" + title + "</h4>" + EOL + "</div>";
     }
 
     /** {@inheritDoc} */
     protected String getSection4Block( String title )
     {
-        return "<div class=\"section\"><h5>" + title + "</h5></div>";
+        return "<div class=\"section\">" + EOL + "  <h5>" + title + "</h5>" + EOL + "</div>";
     }
 
     /** {@inheritDoc} */
     protected String getSection5Block( String title )
     {
-        return "<div class=\"section\"><h6>" + title + "</h6></div>";
+        return "<div class=\"section\">" + EOL + "  <h6>" + title + "</h6>" + EOL + "</div>";
     }
 
     /** {@inheritDoc} */
     protected String getListBlock( String item )
     {
-        return "<ul><li>" + item + "</li></ul>";
+        return "<ul>" + EOL + "  <li>" + item + "</li>" + EOL + "</ul>";
     }
 
     /** {@inheritDoc} */
     protected String getNumberedListBlock( String item )
     {
-        return "<ol style=\"list-style-type: lower-roman\"><li>" + item + "</li></ol>";
+        return "<ol style=\"list-style-type: lower-roman\">" + EOL + "  <li>" + item + "</li>" + EOL + "</ol>";
     }
 
     /** {@inheritDoc} */
     protected String getDefinitionListBlock( String definum, String definition )
     {
-        return "<dl><dt>" + definum + "</dt><dd>" + definition + "</dd></dl>";
+        return "<dl>" + EOL + "  <dt>" + definum + "</dt>" + EOL + "  <dd>" + definition + "</dd>" + EOL + "</dl>";
     }
 
     /** {@inheritDoc} */
@@ -154,8 +155,8 @@
     protected String getTableBlock( String cell, String caption )
     {
         return "<table border=\"0\" class=\"bodyTable\" align=\"center\">"
-            + "<tr class=\"a\"><td align=\"center\">cell</td></tr>"
-            + "<caption>Table caption</caption></table>";
+            + EOL + "  <tr class=\"a\">" + EOL + "    <td align=\"center\">cell</td>" + EOL + "  </tr>"
+            + EOL + "  <caption>Table caption</caption>" + EOL + "</table>";
     }
 
     // Disable testTable until the order of attributes issue is clarified
@@ -175,13 +176,13 @@
     /** {@inheritDoc} */
     protected String getVerbatimBlock( String text )
     {
-        return "<div class=\"source\"><pre>" + text + "</pre></div>";
+        return "<div class=\"source\">" + EOL + "  <pre>" + text + "</pre>" + EOL + "</div>";
     }
 
     /** {@inheritDoc} */
     protected String getHorizontalRuleBlock()
     {
-        return "<hr />";
+        return "<hr/>";
     }
 
     /** {@inheritDoc} */
@@ -223,7 +224,7 @@
     /** {@inheritDoc} */
     protected String getLineBreakBlock()
     {
-        return "<br />";
+        return "<br/>";
     }
 
     /** {@inheritDoc} */
Index: pom.xml
===================================================================
--- pom.xml	(revision 698178)
+++ pom.xml	(working copy)
@@ -190,7 +190,7 @@
       <dependency>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-utils</artifactId>
-        <version>1.5.6</version>
+        <version>1.5.7-SNAPSHOT</version>
       </dependency>
     </dependencies>
   </dependencyManagement>
@@ -203,6 +203,20 @@
     </dependency>
   </dependencies>
 
+  <!-- TODO: TAKE THIS OUT BEFORE WE RELEASE! -->
+  <repositories>
+    <repository>
+      <id>codehaus.snapshots</id>
+      <url>http://snapshots.repository.codehaus.org/</url>
+      <snapshots>
+        <enabled>true</enabled>
+      </snapshots>
+      <releases>
+        <enabled>false</enabled>
+      </releases>
+    </repository>
+  </repositories>
+
   <reporting>
     <plugins>
       <plugin>
