문제가 있습니다. XML의 특정 부분을 linq 쿼리로 업데이트하려고하지만 작동하지 않습니다. 그래서 내가 xml 파일 :xml 쿼리를 수행 할 때 작동하지 않는 linq로 업데이트
<?xml version="1.0" encoding="utf-8"?>
<DesignConfiguration>
<Design name="CSF_Packages">
<SourceFolder>C:\CSF_Packages</SourceFolder>
<DestinationFolder>C:\Documents and Settings\xxx</DestinationFolder>
<CopyLookups>True</CopyLookups>
<CopyImages>False</CopyImages>
<ImageSourceFolder>None</ImageSourceFolder>
<ImageDesinationFolder>None</ImageDesinationFolder>
</Design>
</DesignConfiguration>
나는 부분을 선택하려는 경우이 부분을 의미 후손 값을 업데이트 한 후 자손을 얻고있다 Design name="somethning"
을하고 부분 : 내가 가지고있는
<SourceFolder>C:\CSF_Packages</SourceFolder>
<DestinationFolder>C:\Documents and Settings\xxx</DestinationFolder>
<CopyLookups>True</CopyLookups>
<CopyImages>False</CopyImages>
<ImageSourceFolder>None</ImageSourceFolder>
<ImageDesinationFolder>None</ImageDesinationFolder>
을 이 코드 :
XDocument configXml = XDocument.Load(configXMLFileName);
var updateData = configXml.Descendants("DesignConfiguration").Elements().Where(el => el.Name == "Design" &&
el.Attribute("name").Value.Equals("CSF_Packages")).FirstOrDefault();
configXml.Save(configXMLFileName);
은 내가 updateData
varibale에 널 데이터를 얻고있다. QuickWatch를 통해 Descendat의 기능을 시도 할 때 null 값을 반환합니다. configXML 변수를 검사 할 때 내 전체 XML 데이터가 있습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
var updateData =
confixXml
.Root //Root Element
.Elements("Design") //All elements under root called Design
.Where(element => (String)element.Attribute("name") == "AFP_GRAFIKA") //Find the one with the name Attribute of AFP_GRAFIKA
.FirstOrDefault(); //Grab the first one it finds or return null.
if (updateData != null)
{
var myElements =
updateData
.Elements(); //All the elements under the Design node
}
실제로 'name' 속성의 값이 "AFP_GRAFIKA"인 요소가 있습니까? 해당 속성의 샘플 값은 "CSF_Packages"... –
예를 들어 테스트 중이므로 코드를 보냈습니다. 어디에서 그 일을 유감스럽게 생각하고 있었습니까? –
샘플에서는 문제가 없지만 "AFP_GRAFIKA"대신 "CSF_Packages"를 검색하면 코드가 XML을 검색하는 것으로 나타났습니다. 값이 "AFP_GRAFIKA"인'name' 속성의 경로가 diffe입니다 'DesignConfiguration \ Design'보다 임대. –