빌드중인 응용 프로그램의 일부가 XML 문서에서 robots.txt 파일을 생성해야합니다.부모 노드가 LINQ to XML의 특정 값과 같을 때 자식 노드를 선택하는 방법
나는 XML과 같이 있습니다
<root>
<Robots>
<UserAgents>
<UserAgent>*</UserAgent>
<Disallow>
<Item>/wibble/</Item>
<Item>/wobble/</Item>
</Disallow>
</UserAgents>
<UserAgents>
<UserAgent>Google</UserAgent>
<Disallow>
<Item>/</Item>
</Disallow>
</UserAgents>
</Robots>
</root>
가 어떻게이 "항목"사용자 에이전트 = "*"를 선택 할 수 있습니까?
다른 말로하면 부모 노드가 특정 값과 같을 때만 자식 노드를 선택하고 싶습니다. 상위 노드의 값은 고유합니다.
ASP.net에서 C#을 사용하고 있습니다. 두 번째 from
는 그냥 시퀀스의 순서가되지 않도록 결과를 평평하게하기 위해 사용되는
var query = from agent in doc.Descendants("UserAgent")
where (string) agent == "*"
from item in agent.Parent.Elements("Disallow").Elements("Item")
select item;
참고 :