问题
I am having a XML
in the below mentioned format. I am using Get XML in pentaho to parse this. But I am not able get correct path to get all the values.
I want all the values of 'custom-attributes'.
It is only giving me the value of only first attribute .i.e for 'sex' only. Could anyone please help me how to get the values of other custom-attributes.
I have given the 'LoopXpath' setting as :- /names/name
After pressing 'Get fields' in fields tab as. I am automatically getting the custom-attribute xpath in Fields tab as mentioned below:- And it is giving the value of 'sex' only.
Name |Xpath |Element | ResultType |Type
----------------------------------------------------------------------------------------------
custom-attributes |custom-attributes/custom-attribute |Node |Value of |String
<names>
<name>
<firstname>ABCDEH</firstname>
<lastname>JKLAM</lastname>
<custom-attributes>
<custom-attribute attribute-id="sex">male</custom-attribute>
<custom-attribute attribute-id="height">169</custom-attribute>
<custom-attribute attribute-id="weight">78</custom-attribute>
<custom-attribute attribute-id="dateofbirth">09/09/1990</custom-attribute>
<custom-attribute attribute-id="occupation">engineer</custom-attribute>
</custom-attributes>
</name>
</names>
At last I want a single row like mentioned below:-
firstname lastname sex height weight dateofbirth occupation
ABCDEH JKLAM male 160 78 09/09/1990 engineer
Could anyone please help me in that
回答1:
I am not sure what you have done in your code. Firstly in the "Loop XPATH" settings section of the step, define the parent node path instead of the 'custom-attribute' path (like you have mentioned above) as below:
/names/name/custom-attributes//*
Secondly when you get fields attribute i.e the "custom-attribute", you will need to specify the XPATH
as '.' (dot). This will do the recursion of the attribute values. Check the image below:

Finally you will get the recursive data as :

I have placed a sample code in here. Please check it out for ref.
Hope it helps :)
来源:https://stackoverflow.com/questions/28348709/how-to-extract-xml-node-values-and-from-recurring-nodes-in-pentaho