LINQ to XML 和 WIX 问题
我有一个包含 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 属性。想法?
I have a WIX XML document that contains 2,000+ file tags. I am trying to make a program using LINQ to XML that can update an attribute of each file tag. My code is as follows for loading the current attributes into a dictionary.
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]);
}
now the problem is that my program says that the IEnumerable fileID and path both contain only "null" but I know that the file tag exists and that every one of them has an ID and Source attribute. Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
属性不需要命名空间,请尝试:
Attributes don't require namespaces, try:
尝试访问属性时不要使用命名空间。我注意到,当您使用 Descendant 和 Element 等方法时,只需要命名空间。
所以你的代码应该是(例如)
Don't use the namespace when trying to access the Attribute. I've noticed that you only need the namespace when you're using methods like Descendant and Element.
So your code should be (for example)