Hello, 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 cand I do it? Thank you
A:
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])
Ryan Berger
2010-08-30 15:37:23
+2
A:
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])
Alejandro
2010-08-30 15:40:30
+1. This is assuming that the OP wants the first *element* child, which is probably a valid assumption.
LarsH
2010-08-30 16:16:35
@LarsH: You are right about element selection assumption
Alejandro
2010-08-30 16:20:16