NXMLFormatter
NXMLFormatter is an open-source XML Formatter and beautifier written with C#. The DLL is available as a portable class library, so you can use it from UWP, ASP.NET etc.
Usage
- Add reference to NXMLFormatter.dll.
- var formattedXML = NXMLFormatter.Formatter.Format(originalXML);
Project doesn't have any external references and it uses only the features provided by the .NET Framework.
NuGet
NXMLFormatter is available through the NuGet with the package name NXMLFormatter. Type "install-package NXMLFormatter" to install it.
Example
Input
<catalog><book id="bk101"><author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description> </book> <book id="bk102"> <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description></book> <book id="bk103"> <author>Corets, Eva</author> <title>Maeve Ascendant</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-11-17</publish_date> <description>After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society.</description></book></catalog>
Output
<catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id="bk102"> <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description> </book> <book id="bk103"> <author>Corets, Eva</author> <title>Maeve Ascendant</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-11-17</publish_date> <description>After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society.</description> </book> </catalog>
Implementation
Under the covers the library uses XmlWriter to format the code.
Licenses
The library is distributed under the terms of the MIT License (see mit.txt).