gpt4 book ai didi

c# - LINQ to XML 和 WIX 问题

转载 作者:行者123 更新时间:2023-11-30 21:23:09 25 4
gpt4 key购买 nike

我有一个包含 2,000 多个文件标签的 WIX XML 文档。我正在尝试使用 LINQ to XML 制作一个程序,该程序可以更新每个文件标签的属性。我的代码如下,用于将当前属性加载到字典中。

 XElement root = XElement.Load(filePath);
XNamespace wix = @"http://schemas.microsoft.com/wix/2006/wi";

IEnumerable<string> fileId =
from seg in root.Descendants(wix + "File")
select (string)seg.Attribute(wix + "Id");

IEnumerable<string> path =
from seg in root.Descendants(wix + "File")
select (string)seg.Attribute(wix + "Source");

string[] Position1 = fileId.ToArray();
string[] Position2 = path.ToArray();

for (int i = 0; i < Position1.Length; i++)
{
xmlDataRaw.Add(Position1[i], Position2[i]);
}

现在的问题是我的程序说 IEnumerable fileID 和路径都只包含“null”,但我知道文件标签存在并且每个标签都有 ID 和 Source 属性。想法?

最佳答案

属性不需要命名空间,试试:

IEnumerable<string> fileId =
from seg in root.Descendants(wix + "File")
select (string)seg.Attribute("Id");

IEnumerable<string> path =
from seg in root.Descendants(wix + "File")
select (string)seg.Attribute("Source");

关于c# - LINQ to XML 和 WIX 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1952733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com