How to select a node's first child name? XPath

后端 未结 3 1069
你的背包
你的背包 2021-02-03 17:57

I have an XML from which I have to select the name of the child of one of the nodes. I\'m kind of a beginner in this, so I didn\'t find the Xpath expression to do it. I know the

相关标签:
3条回答
  • 2021-02-03 17:59

    You wrote:

    I have to select the first child of Department node

    You could use:

    /Employee/Department/*[1]
    

    Then, you also wrote:

    I have an XML from which I have to select the name of the child of one of the nodes

    So, you could use:

    name(/Employee/Department/*[1])
    
    0 讨论(0)
  • 2021-02-03 18:10

    I don't know the exact context of your XML, but I believe this is the XPath you are looking for...

    /Employee/Department/*[1]
    

    The key part of this XPath is *[1], which will select the node value of the first child of Department.

    If you need the name of the node, then you will want to use this...

    name(/Employee/Department/*[1])
    
    0 讨论(0)
  • 2021-02-03 18:25

    You need something like:

    local-name(/Employee/Department/*[1])
    
    0 讨论(0)
提交回复
热议问题