2
XML을 쿼리 할 때 Linq을 자주 사용하지 않으며 XML에 대한 많은 경험이 없습니다. 내가 뭘하고 싶은 것은Linq를 사용하여 XML 문서 쿼리
<AlarmParameters>
<Parameter>
<ParameterName>ConsecutivePoints</ParameterName>
<Points>30</Points>
<AllowEdit>true</AllowEdit>
<Caption>Consecutive Points</Caption>
</Parameter>
<Parameter>
<ParameterName>SigmaCount</ParameterName>
<Count>1</Count>
<AllowEdit>true</AllowEdit>
<Caption>Number of Sigmas</Caption>
</Parameter>
</AlarmParameters>
...이 간단한 XML 문서를 조회 ... 그리고 '매개 변수'클래스 목록을 생산하는 것입니다, 속성을 포함하는 각는 XML 예제에 표시된. LinqPad를 사용하여, 나는 이것을 멀리까지 얻을 수 있었지만, 이것을 어떻게 완성 할 지 정말로 모른다.
string xmlFragment = "<AlarmParameters><Parameter><ParameterName>ConsecutivePoints</ParameterName><Points>30</Points><AllowEdit>true</AllowEdit><Caption>Consecutive Points</Caption></Parameter><Parameter><ParameterName>SigmaCount</ParameterName><Count>1</Count><AllowEdit>true</AllowEdit><Caption>Number of Sigmas</Caption></Parameter></AlarmParameters>";
StringReader strReader = new StringReader(xmlFragment);
XDocument xmlDoc = XDocument.Load(strReader);
var result = from parameter in xmlDoc (not sure what Linq to put here next)
거의 완벽합니다. 이 쿼리를 실행할 때 클래스 속성 값에 요소 이름에 포함 된 값이 포함되어 있음을 확인했습니다 (예 :) 요소 이름을 없애고 값을 얻는 방법은 무엇입니까? – Hosea146
아, 예, 사용할 수 있습니다. 'Element (".."). Value'. – mellamokb
당신은 나의 날을 만들었습니다! – Hosea146