diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-03-26 15:21:06 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-03-30 21:30:04 +1000 |
| commit | afbc6889c73d58136cb8851858ca3c17f41dc2c5 (patch) | |
| tree | 1d7c66218176c7e8a28d49a4e22c60fe1e4e4c0d /src/WixToolset.Core.TestPackage/XmlNodeExtensions.cs | |
| parent | 192c5aa59b5d8e5e9df9095982317c224f3d4f04 (diff) | |
| download | wix-afbc6889c73d58136cb8851858ca3c17f41dc2c5.tar.gz wix-afbc6889c73d58136cb8851858ca3c17f41dc2c5.tar.bz2 wix-afbc6889c73d58136cb8851858ca3c17f41dc2c5.zip | |
Add BundleExtension element.
Add GetTestXml.
Fix issue with building with current version of burn.
Diffstat (limited to 'src/WixToolset.Core.TestPackage/XmlNodeExtensions.cs')
| -rw-r--r-- | src/WixToolset.Core.TestPackage/XmlNodeExtensions.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/WixToolset.Core.TestPackage/XmlNodeExtensions.cs b/src/WixToolset.Core.TestPackage/XmlNodeExtensions.cs new file mode 100644 index 00000000..a7f04508 --- /dev/null +++ b/src/WixToolset.Core.TestPackage/XmlNodeExtensions.cs | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixToolset.Core.TestPackage | ||
| 4 | { | ||
| 5 | using System.Collections.Generic; | ||
| 6 | using System.IO; | ||
| 7 | using System.Text.RegularExpressions; | ||
| 8 | using System.Xml; | ||
| 9 | |||
| 10 | public static class XmlNodeExtensions | ||
| 11 | { | ||
| 12 | public static string GetTestXml(this XmlNode node, Dictionary<string, List<string>> ignoredAttributesByElementName = null) | ||
| 13 | { | ||
| 14 | return node.OuterXml.GetTestXml(ignoredAttributesByElementName); | ||
| 15 | } | ||
| 16 | |||
| 17 | public static string GetTestXml(this string xml, Dictionary<string, List<string>> ignoredAttributesByElementName = null) | ||
| 18 | { | ||
| 19 | string formattedXml; | ||
| 20 | using (var sw = new StringWriter()) | ||
| 21 | using (var writer = new TestXmlWriter(sw)) | ||
| 22 | { | ||
| 23 | var doc = new XmlDocument(); | ||
| 24 | doc.LoadXml(xml); | ||
| 25 | |||
| 26 | if (ignoredAttributesByElementName != null) | ||
| 27 | { | ||
| 28 | HandleIgnoredAttributes(doc, ignoredAttributesByElementName); | ||
| 29 | } | ||
| 30 | |||
| 31 | doc.Save(writer); | ||
| 32 | formattedXml = sw.ToString(); | ||
| 33 | } | ||
| 34 | |||
| 35 | return Regex.Replace(formattedXml, " xmlns(:[^=]+)?='[^']*'", ""); | ||
| 36 | } | ||
| 37 | |||
| 38 | private static void HandleIgnoredAttributes(XmlNode node, Dictionary<string, List<string>> ignoredAttributesByElementName) | ||
| 39 | { | ||
| 40 | if (node.Attributes != null && ignoredAttributesByElementName.TryGetValue(node.LocalName, out var ignoredAttributes)) | ||
| 41 | { | ||
| 42 | foreach (var ignoredAttribute in ignoredAttributes) | ||
| 43 | { | ||
| 44 | var attribute = node.Attributes[ignoredAttribute]; | ||
| 45 | if (attribute != null) | ||
| 46 | { | ||
| 47 | attribute.Value = "*"; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | if (node.ChildNodes != null) | ||
| 53 | { | ||
| 54 | foreach (XmlNode childNode in node.ChildNodes) | ||
| 55 | { | ||
| 56 | HandleIgnoredAttributes(childNode, ignoredAttributesByElementName); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | private class TestXmlWriter : XmlTextWriter | ||
| 62 | { | ||
| 63 | public TestXmlWriter(TextWriter w) | ||
| 64 | : base(w) | ||
| 65 | { | ||
| 66 | this.QuoteChar = '\''; | ||
| 67 | } | ||
| 68 | |||
| 69 | public override void WriteStartDocument() | ||
| 70 | { | ||
| 71 | //OmitXmlDeclaration | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
