Nikhil Agrawal
Nikhil Agrawal

Reputation: 48568

How to convert continous XML to indented XML?

I have an xml

<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph TextAlignment="Left" FontFamily="Arial" NumberSubstitution.CultureSource="User"><Run FontSize="15">Foo Bar</Run></Paragraph></FlowDocument>

I want to convert this to

<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <Paragraph TextAlignment="Left" FontFamily="Arial" NumberSubstitution.CultureSource="User">
        <Run FontSize="15">Foo Bar</Run>
    </Paragraph>
</FlowDocument>

I don't know how to do this? This XML is generated dynamically by XamlWriter.Save and what this function returns becomes text of a textbox like this

TxtBox1.Text = XamlWriter.Save(MyFlowDocument);

Upvotes: 0

Views: 166

Answers (1)

Plymouth223
Plymouth223

Reputation: 1925

Load the text into an XDocument (see XDocument.Parse) and then use XDocument.ToString on the new instance.

Upvotes: 1

Related Questions