How to Compare XML Strings Using .NET

So you want to compare two XML strings together to see if they are equal. Obviously, it would be easy to just compare the two strings using a regular string equality comparison and call it a day. However, what if the XML strings looked like the following:

<SampleXML>
    <SampleField1>Testing</SampleField1>
    <SampleField2 value="test value" />
    <SampleField3 type="int">456</SampleField3>
</SampleXML>
<SampleXML>
        <SampleField1>Testing</SampleField1>
    <SampleField2     value="test value" />
        <SampleField3 type="int">456</SampleField3></SampleXML>

All of the nodes, attributes and values are the same, but the formatting is way off. Obviously, a string equality comparison between these two would return false. Is there anything that can be done about this? Not to fear, .NET provides a pretty simple solution. Continue reading