如何从pentaho中的重复节点中提取XML节点值? [英] How to extract XML node values and from recurring nodes in pentaho?

查看:102
本文介绍了如何从pentaho中的重复节点中提取XML节点值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下格式的XML.我在pentaho中使用Get XML对此进行解析.但是我无法获得所有值的正确路径. 我需要"自定义属性"的所有值.

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.

我已将' LoopXpath '设置为:-/names/name

I have given the 'LoopXpath' setting as :- /names/name

在字段"标签中按"获取字段"后.我会在字段"选项卡中自动获取自定义属性xpath,如下所述: 而且它只是赋予性别"的价值.

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

有人可以帮我吗

推荐答案

我不确定您在代码中做了什么.首先,在该步骤的"循环XPATH "设置部分中,定义父节点路径,而不是" custom-attribute "路径(就像您上面提到的那样) )如下:

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//*

第二,当您获得字段属性(即"自定义属性")时,您需要将XPATH指定为"."(点).这将进行属性值的递归.查看下面的图片:

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 :)

这篇关于如何从pentaho中的重复节点中提取XML节点值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆