XElement - Xpath RRS feed

  • Question

  • User364803292 posted


    How can I select a spesific attribute from an XElement object using XPath?

    Wednesday, April 9, 2014 3:02 AM


All replies

  • User697462465 posted

    Hi Taonias,

    There have a sample, maybe helps:

    Imports System
    Imports System.Xml
    Imports System.Xml.XPath
    Public Class MainClass
        Public Shared Sub Main()
            Dim root As XElement = _
            Dim el As XElement = root.XPathSelectElement("./Child4")
        End Sub
    End Class



    Best Regards,
    Terry Guo

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Thursday, April 10, 2014 5:48 AM
  • User364803292 posted

    Thanks for replying

    This is my xml:

    <RootNode testAttr="my attr">
      <SubNode subAttr="My sub attr">
        My Sub Text

    suppose i need to select the value of the attribute testAttr what would be the xpath for that?

    Thursday, April 10, 2014 8:59 AM
  • User697462465 posted

    Hi Taonias,

    Please use the following XPath:


    More information about XPath please refer to:

    Hope it helps.

    Best Regards,
    Terry Guo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 11, 2014 4:43 AM