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:
@class
- to get class@version
- to get the version*[name()='list']/*[name()='p']
- to get "Power On"*[name()='p']/@name
- to get identificationCode
(first p name)*[name()='p']
- to get the value of identificationCode
- 9999ASimilar to the last two fields, I want to get the rest of the elements using XPath:
operationalState
- 1position
- 1serialNumber
- 8888BunitId
- 1How do I do this?
There are 2 locations where you specify an XPath expression in step Get-Data-From-XML:
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.