private void ProcessPatchXml(WixBundlePayloadSymbol packagePayload, WixBundleMspPackageSymbol mspPackage, string sourcePath)
        {
            var uniqueTargetCodes = new HashSet <string>();

            var patchXml = Dtf.Installer.ExtractPatchXmlData(sourcePath);

            var doc = new XmlDocument();

            doc.LoadXml(patchXml);

            var nsmgr = new XmlNamespaceManager(doc.NameTable);

            nsmgr.AddNamespace("p", "http://www.microsoft.com/msi/patch_applicability.xsd");

            // Determine target ProductCodes and/or UpgradeCodes.
            foreach (XmlNode node in doc.SelectNodes("/p:MsiPatch/p:TargetProduct", nsmgr))
            {
                // If this patch targets a product code, this is the best case.
                var targetCodeElement = node.SelectSingleNode("p:TargetProductCode", nsmgr);
                var attributes        = WixBundlePatchTargetCodeAttributes.None;

                if (ProcessMspPackageCommand.TargetsCode(targetCodeElement))
                {
                    attributes = WixBundlePatchTargetCodeAttributes.TargetsProductCode;
                }
                else // maybe targets an upgrade code?
                {
                    targetCodeElement = node.SelectSingleNode("p:UpgradeCode", nsmgr);
                    if (ProcessMspPackageCommand.TargetsCode(targetCodeElement))
                    {
                        attributes = WixBundlePatchTargetCodeAttributes.TargetsUpgradeCode;
                    }
                    else // this patch targets an unknown number of products
                    {
                        mspPackage.Attributes |= WixBundleMspPackageAttributes.TargetUnspecified;
                    }
                }

                var targetCode = targetCodeElement.InnerText;

                if (uniqueTargetCodes.Add(targetCode))
                {
                    this.Section.AddSymbol(new WixBundlePatchTargetCodeSymbol(packagePayload.SourceLineNumbers)
                    {
                        PackageRef = packagePayload.Id.Id,
                        TargetCode = targetCode,
                        Attributes = attributes
                    });
                }
            }

            // Suppress patch sequence data for improved performance.
            var root = doc.DocumentElement;

            foreach (XmlNode node in root.SelectNodes("p:SequenceData", nsmgr))
            {
                root.RemoveChild(node);
            }

            // Save the XML as compact as possible.
            using (var writer = new StringWriter())
            {
                var settings = new XmlWriterSettings()
                {
                    Encoding        = ProcessMspPackageCommand.XmlOutputEncoding,
                    Indent          = false,
                    NewLineChars    = String.Empty,
                    NewLineHandling = NewLineHandling.Replace,
                };

                using (var xmlWriter = XmlWriter.Create(writer, settings))
                {
                    doc.WriteTo(xmlWriter);
                }

                mspPackage.PatchXml = writer.ToString();
            }
        }