'XPath for Workday
I'm really new with XPath and would appreciate your expert advice!
<wd:Get_Workers_Response xmlns:wd="urn:com.workday/bsvc" wd:version="v24.1">
<wd:Response_Data>
<wd:Worker>
<wd:Worker_Data>
<wd:Employment_Data>
<wd:Position_Data wd:Effective_Date="2022-04-17-07:00">
<wd:Job_Classification_Summary_Data>
<wd:Job_Classification_Reference wd:Descriptor="Some Value">
<wd:ID wd:type="WID">6abcdefghijklmnopqrstuvwxyzabcd2</wd:ID>
<wd:ID wd:type="Job_Classification_Reference_ID">Some_Value</wd:ID>
</wd:Job_Classification_Reference>
<wd:Job_Group_Reference wd:Descriptor="MIP">
<wd:ID wd:type="WID">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</wd:ID>
<wd:ID wd:type="Job_Classification_Group_ID">JOB_CLASSIFICATION_GROUP_MIP</wd:ID>
</wd:Job_Group_Reference>
</wd:Job_Classification_Summary_Data>
</wd:Position_Data>
</wd:Employment_Data>
</wd:Worker_Data>
</wd:Worker>
</wd:Response_Data>
</wd:Get_Workers_Response>
I'd like to get the value "Some_value" in <wd:ID wd:type="Job_Classification_Reference_ID">Some_Value</wd:ID> where WID=6abcdefghijklmnopqrstuvwxyzabcd2
Can you tell me the xpath for that?
Solution 1:[1]
This XPath expression:
string(//wd:ID[@wd:type = 'Job_Classification_Reference_ID']/text())
when evaluated against the provided XML document (with added arbitrary namespace-uri for the prefix 'wd:' to make it wellformed):
<wd:Response_Data xmlns:wd="urn:com.workday/xxx">
<wd:Worker>
<wd:Worker_Data>
<wd:Employment_Data>
<wd:Position_Data wd:Effective_Date="2022-04-17-07:00">
<wd:Job_Classification_Summary_Data>
<wd:Job_Classification_Reference wd:Descriptor="Some Value">
<wd:ID wd:type="WID">6abcdefghijklmnopqrstuvwxyzabcd2</wd:ID>
<wd:ID wd:type="Job_Classification_Reference_ID">Some_Value</wd:ID>
</wd:Job_Classification_Reference>
<wd:Job_Group_Reference wd:Descriptor="MIP">
<wd:ID wd:type="WID">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</wd:ID>
<wd:ID wd:type="Job_Classification_Group_ID">JOB_CLASSIFICATION_GROUP_MIP</wd:ID>
</wd:Job_Group_Reference>
</wd:Job_Classification_Summary_Data>
</wd:Position_Data>
</wd:Employment_Data>
</wd:Worker_Data>
</wd:Worker>
</wd:Response_Data>
Selects the string value of the wanted text node:
Some_Value
Do note:
In your XPath engine you need to register a 'wd:' prefix and associate it with the "urn:com.workday/xxx" namespace.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dimitre Novatchev |
