0

次の内容のファイルがあります (myfile.xml)。すべてのコンテンツを (製品ノードを含む) 製品の下に取得する必要がありますid=1

<products>  
  <product id="1">
       <category>q</category>  
  </product>    
  <product id="2">      
       <category>w</category>    
  </product>   
  <product id="3">       
  <category>e</category>   
 </product>
</products>`

つまり、結果は次のようになります。

 <product id="1"> 
      <category>q</category>
  </product> 

これどうやってするの?

4

2 に答える 2

0
var root = XElement.Load("path to the file");
var node = root.Descendants("product").FirstOrDefault(e=>e.Attribute("id").Value == "1");
于 2012-05-16T12:07:28.340 に答える