저는 LINQ를 처음 사용하고있어서 문제가 있습니다. 내가 원하는 갤러리의 ID를 알고, 어쨌든LINQ를 사용하여 임의의 XML 노드 선택
<?xml version="1.0" encoding="utf-8" ?>
<Galleries>
<Gallery ID="10C31804CEDB42693AADD760C854ABD" Title="Test1">
<Description>The first test gallery. Picture of a cat and Wilford Brimley. Can you tell the difference?</Description>
<Images>
<Image Title="t1Image1" FileName="tcats.jpg" />
<Image Title="t1Image2" FileName="twb.jpg" />
</Images>
</Gallery>
<Gallery ID="0420EC15405B488E1E0F157AC823A6" Title="Test2">
<Description>The second test gallery. A large image of Wilford Brimley and various cats. The cats will be on the right.</Description>
<Images>
<Image Title="t2Image1" FileName="wilfordbrimley.jpg" />
</Images>
</Gallery>
</Galleries>
,하지만 난 임의의 이미지 중 하나를 선택합니다 : 내가 이렇게 보이는 파일이 있습니다. 이 작업을 수행 할 수있는 LINQ 문이 있습니까?
매우 영리한 솔루션 따라서, 나는 다음과 같은 사용합니다. –
Random.Next()를 사용하여 무작위 갤러리를 선택하는 방법을 알아 냈습니다.하지만 Gallery ID를받은 갤러리에서 임의의 이미지를 선택하려면 어떻게해야합니까? 죄송합니다, LINQ가 지금 내 머리 위로 가고 있습니다. –
@OSMan : 갤러리가 포함 된'XElement' 또는'XNode'를 사용하는 경우'node.Element ("Images")'를 사용하여 images 요소를 가져옵니다. –