开发者

Removing attributes from elements

I will start off with the code...

private static void File()
{
    wixFile = XDocument.Load(filePath);

    var fileElements = from file in wixFile.Descendants(GetWixNamespace() + "File")
                        select file;
    foreach (var file in fileElements)
    {
        if(file.Attributes("Name").Any())
            file.Attribute("Name").Remove();
    }
    wixFile.Save(fileP开发者_如何学JAVAath);
}

I actually check for quite a few attributes in the list and remove or correct them, but just to keep it short I took everything out except for one example of what I was doing. The problem that I am having is that this code is not removing the Name attribute from anything like I would expect it. When I put a break point in and watch it the "file" is getting updated as expected, but the changes are not going over to the wixFile when I save (or during the editing either). I am not entirely sure what I am missing here so any help would be greatly appreciated.

EDIT:

Here is a snippet of the code that is being changed:

<?define ApplicationPath=\\dwdata\develope\DocuWare\DW5\Mast_dsk\?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Directory Id="DATADIR" Name="data">
                            <Directory Id="mysql" Name="mysql">
                                <Component Id="procs_priv.MYI" Guid="{1148181A-4818-434F-B2D1-E4B417586168}">
                                    <File Id="procs_priv.MYI" Name="procs_priv.MYI" KeyPath="yes" Source="$(var.ApplicationPath)Common\MySql\Server\data\mysql\procs_priv.MYI" />
                                </Component>
                                <Component Id="procs_priv.MYD" Guid="{A6688F48-71AF-4242-B6D0-CA69452A01B4}">
                                    <File Id="procs_priv.MYD" Name="procs_priv.MYD" KeyPath="yes" Source="$(var.ApplicationPath)Common\MySql\Server\data\mysql\procs_priv.MYD" />
                                </Component>
                                <Component Id="procs_priv.frm" Guid="{3025C26C-8DFF-43D4-A62A-79E78D2D807D}">
                                    <File Id="procs_priv.frm" Name="procs_priv.frm" KeyPath="yes" Source="$(var.ApplicationPath)Common\MySql\Server\data\mysql\procs_priv.frm" />
                                </Component>
                                <Component Id="proc.MYI" Guid="{FD4AA2E1-E059-4549-AE61-222878185A0A}">
                                    <File Id="proc.MYI" Name="proc.MYI" KeyPath="yes" Source="$(var.ApplicationPath)Common\MySql\Server\data\mysql\proc.MYI" />
                                </Component>
                                <Component Id="proc.MYD" Guid="{12EE6EE8-AC44-4601-84C5-14B27CF9A3E6}">
                                    <File Id="proc.MYD" Name="proc.MYD" KeyPath="yes" Source="$(var.ApplicationPath)Common\MySql\Server\data\mysql\proc.MYD" />
                                </Component>
                                <Component Id="proc.frm" Guid="{8A6F2928-5484-4B55-B75F-8475C684A091}">
                                    <File Id="proc.frm" Name="proc.frm" KeyPath="yes" Source="$(var.ApplicationPath)Common\MySql\Server\data\mysql\proc.frm" />
                                </Component>
</Directory>
</Directory>
</Wix>

I am getting the exact same thing back as well. What I am trying to do is remove the "Name" attribute, but it just isn't working for whatever reason. The GetWiXNamespace() method returns the same namespace that is listed in the wix element as an XNamespace.


I'm going to read between the lines here and guess you are converting from an old version of WiX ( say 2.0 ) that required a File@Name attribute to a version ( say 3.0-3.6 ) that can infer this attribute and doesn't require it.

Here's some code that I just whipped up that I know works assuming the source xml is WiX 3.x. I'm not sure what is wrong with your code but perhaps the method that returns the namespace hasn't accounted for the url change.

    XNamespace ns = "http://schemas.microsoft.com/wix/2006/wi";
    var doc = XDocument.Load(@"C:\before.wxs");
    var elements = from element in doc.Descendants( ns + "File")
                   where element.Attribute("Name") != null
                   select element;

    foreach (var element in elements)
    {
        element.Attribute("Name").Remove();
    }
    doc.Save(@"C:\after.wxs");


<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?define SourceDir="."?>
  <Module Id="YourModuleHere" Language="1033" Version="1.0.0.0">
    <Package Id="31c7722e-c2a0-4328-92a2-eacd443c10a9" Manufacturer="YourCompanyHere" InstallerVersion="200" />
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="MergeRedirectFolder">
        <Component Id="owc7CEF9B0C53324FC23404D2AAAB5D12B8" Guid="6898e947-fa51-8efb-bda4-2e256dea8ed1">
          <File Id="owf7CEF9B0C53324FC23404D2AAAB5D12B8" Name="bfsvc.exe" Source="$(var.SourceDir)\Windows\bfsvc.exe" KeyPath="yes" />
        </Component>
        <Component Id="owc8C6EA26177072C0006EEF8265FEF72A4" Guid="91737806-0b20-24ad-9653-cca05b5778fb">
          <File Id="owf8C6EA26177072C0006EEF8265FEF72A4" Name="explorer.exe" Source="$(var.SourceDir)\Windows\explorer.exe" KeyPath="yes" />
        </Component>
      </Directory>
    </Directory>
  </Module>
</Wix>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜