xpathworkday-api

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

  • When you can declare a prefix for the used namespace use this XPath:

    //wd:ID[@wd:type='WID' and text()='6abcdefghijklmnopqrstuvwxyzabcd2']/following-sibling::wd:ID[1]/text()
    

    Or as an faster alternative while the XPath is more explicit, use this XPath:

    //wd:Job_Classification_Summary_Data/wd:Job_Classification_Reference[wd:ID[@type='WID']/text() = '6abcdefghijklmnopqrstuvwxyzabcd2']]/wd:ID[@type='Job_Classification_Reference_ID']/text()
    

    If you are not able do use a prefix use this XPath:

    //*[local-name()='ID'][@*[local-name()='type' and .='WID'] and text()='6abcdefghijklmnopqrstuvwxyzabcd2']/following-sibling::*[local-name()='ID'][1]/text()