How would you compare two XML Documents?
Microsoft has an XML diff API that you can use. Unofficial NuGet: https://www.nuget.org/packages/XMLDiffPatch.
Microsoft has an XML diff API that you can use. Unofficial NuGet: https://www.nuget.org/packages/XMLDiffPatch.
Based on the other answers, I looked into XmlTextWriter and came up with the following helper method: static public string Beautify(this XmlDocument doc) { StringBuilder sb = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = ” “, NewLineChars = “\r\n”, NewLineHandling = NewLineHandling.Replace }; using (XmlWriter writer = XmlWriter.Create(sb, settings)) … Read more
XmlNodeList elemList = doc.GetElementsByTagName(…); for (int i = 0; i < elemList.Count; i++) { string attrVal = elemList[i].Attributes[“SuperString”].Value; }
You should use an XmlNamespaceManager in your call to SelectSingleNode(): XmlNamespaceManager ns = new XmlNamespaceManager(xmldoc.NameTable); ns.AddNamespace(“msbld”, “http://schemas.microsoft.com/developer/msbuild/2003”); XmlNode node = xmldoc.SelectSingleNode(“//msbld:Compile”, ns);
If you’re using .NET version 3.0 or lower, you have to use XmlDocument aka the classic DOM API. Likewise you’ll find there are some other APIs which will expect this. If you get the choice, however, I would thoroughly recommend using XDocument aka LINQ to XML. It’s much simpler to create documents and process them. … Read more