xmlxpathpentaho-spoon

XPath to select multiple elements


I have an XML as shown below:

<managedObject class="SUBRACK" version="1.0" distName="xxxx-xxxx/BSC-2222/xxx-102/xxx-1/xx-1" id="2222">
  <p name="locationName">000000-000</p>
  <p name="subrackSpecificType">xxxx</p>
  <p name="vendorName">xxxx</p>
  <p name="version">01</p>
</managedObject>
<managedObject class="UNIT" version="1.0" distName="x1-X2/XXX-111111/YYY-102/ZZ-1/AAAA-1/BBBB-CCC_2_3" id="55555">
  <list name="availabilityStatus">
    <p>Power On</p> 
  </list>
  <p name="identificationCode">9999A</p>
  <p name="operationalState">1</p>
  <p name="position">1</p>
  <p name="serialNumber">8888B</p>
  <p name="unitId">1</p>
  <p name="unitType">HHHH</p>
  <p name="vendorName">AAAA</p>
  <p name="version">333</p>
</managedObject>

I want an XPath to select all the p name along with their values.

I am able to get the other values using:

Similar to the last two fields, I want to get the rest of the elements using XPath:

How do I do this?


Solution

  • There are 2 locations where you specify an XPath expression in step Get-Data-From-XML:

    1. The Loop XPath (Content tab) is meant to derive rows from a document by returning a nodelist.
    2. The Field XPath (Fields tab) is meant to populate the fields of a row.

    If your document contains multiple nodelists on different levels, it's best to aim for the deepest list. It's easy to access ancestor information using axes or the .. operator.

    When a field XPath returns a nodelist, Kettle will always pick the first item instead of aborting.

    Obviously you must use //p as your Loop XPath.