2012-01-26 5 views
1

아래의 것과 같이 xml 파일을 C# .NET 2.0으로 어떻게 쿼리 할 수 ​​있습니까? ID 값을 가지고 있으며 해당 ID와 관련된 축소판 이미지를 가져와야합니다..net의 속성으로 xml 파일 쿼리

<root> 
    <categories> 
     <category title="decking"> 
      <photos> 
       <photo id="1" smallphoto="/files/images/photogallery/thumbs/EarthwoodEvolutions1_thumb.jpg" /> 
       <photo id="2" smallphoto="/files/images/photo-gallery/thumbs/XLM401_thumb.jpg" /> 
      </photos> 
     </category> 
    </categories> 
</root> 

답변

1

당신은 너무 간단 :

XmlDocument doc = new XmlDocument(); 
doc.Load(xmlFilename); 

XmlNodeList nodes = doc.SelectNodes("/root/categories/category/photos/photo[@id='" + photoId + "']"); 
XmlNode photoNode = nodes.Item(0); 
// Use thumbnail in photoNode.Attributes["smallphoto"].InnerText