Finding element in XDocument?

前端 未结 7 1623
眼角桃花
眼角桃花 2020-12-02 20:02

I have a simple XML


  
    greatest Band
            


        
7条回答
  •  忘掉有多难
    2020-12-02 20:31

    You can do it this way:

    xml.Descendants().SingleOrDefault(p => p.Name.LocalName == "Name of the node to find")
    

    where xml is a XDocument.

    Be aware that the property Name returns an object that has a LocalName and a Namespace. That's why you have to use Name.LocalName if you want to compare by name.

提交回复
热议问题