If you’d like to render XML as a WPF FlowDocument, give this a try (ClickOnce sample; source available here or on CodePlex).  Here’s a screenshot:


The useful part is the PrettyXmlConverter class (view here; it’s "self documenting":) ).  It’s implemented as an IValueConverter so you can easily include it in binding expressions:

<Window x:Class="XmlFlowDocumentSample.Window1"
    Title="Pretty XML FlowDocument sample">

        <converters:PrettyXmlConverter x:Key="prettyXmlConverter"/>
        <XmlDataProvider x:Key="xmlSource" Source="Xml/Books.xml" IsAsynchronous="False"/>


        <FlowDocumentReader ViewingMode="Scroll" Zoom="300"
                            Document="{Binding Source={StaticResource xmlSource}, Path=Document, BindsDirectlyToSource=true, Converter={StaticResource prettyXmlConverter}}">




Currently it only renders elements and attributes, so no comments, processing instructions or explicit CDATA handling.  These could be added very easily if needed:)

The formatted XML pastes nicely into MS Word (formatting preserved).

DotNetKicks Image