2009-12-23 5 views
2

2,000 개 이상의 파일 태그가 포함 된 WIX XML 문서가 있습니다. 각 파일 태그의 특성을 업데이트 할 수있는 XML에 대한 LINQ를 사용하는 프로그램을 만들려고합니다. 사전에 현재 속성을로드하기위한 코드는 다음과 같습니다. LINQ to XML 및 WIX 문제

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 및 원본 속성을 가지고 있다고 말한다는 것이다. 생각? 네임 스페이스를 필요로하지 않는

+0

확인 (예를 들어)해야한다. – SLaks

답변

3

속성, 시도 : 속성에 액세스하려고 할 때

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"); 
+0

당신은 지금 살아있는 가장 멋진 사람입니다! 그것은 트릭을했다. 감사! – Adkins

+1

이전에 물린 적이 있습니다. / –

1

네임 스페이스를 사용하지 마십시오. Descendant 및 Element와 같은 메서드를 사용할 때 네임 스페이스 만 있으면됩니다.

그래서 코드 네임 스페이스가 올바른지

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