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

Jaq picture Jaq · Aug 30, 2010 · Viewed 93k times · Source

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 level of the node

Example

Name from /Employee/Department/

but Department has children nodes of unknown names. I have to select the first child of Department node. How can I do this?

Answer

user357812 picture user357812 · Aug 30, 2010

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])