Getting data from xml by attribute value C# using

2019-09-11 23:59发布

I have a file with the following content (myfile.xml). I have to get all content coming under (including product node) a product with 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>`

i.e. the result should be :

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

How can I do this?

I have the restriction that I should use XmlTextReader or XPathNavigator only for this, otherwise I could have used this : Getting data from xml by attribute vlaue

1条回答
登录 后发表回答