<p>I am creating a lightweight editor in C# and would like to know the best method for converting a string into a nicely formatted XML string.  I would hope that there's a public method in the C# library like "public bool FormatAsXml(string text, out string formattedXmlText)", but it couldn't be that easy, could it?</p>

<p>Very specifically, what would the method "SomeMethod" have to be that would produce the output below?</p>

<pre><code>string unformattedXml;
string formattedXml;

unformattedXml = "&lt;?xml version=\"1.0\"?&gt;&lt;book&gt;&lt;author&gt;Lewis, C.S.&lt;/author&gt;&lt;title&gt;The Four Loves&lt;/title&gt;&lt;/book&gt;"
formattedXml = SomeMethod(unformattedXml);

Console.WriteLine(formattedXml);
</code></pre>

<p>Output:</p>

<pre><code>&lt;?xml version="1.0"?&gt;
  &lt;book id="123"&gt;
    &lt;author&gt;Lewis, C.S.&lt;/author&gt;
    &lt;title&gt;The Four Loves&lt;/title&gt;
  &lt;/book&gt;
</code></pre>

Is the string valid XML? Do you mean how can you convert an XML string into an XML document? If so, do this:
```
```
XmlDocument xml = new XmlDocument();

xml.LoadXml( YourString );
```
```