如何从pentaho中提取XML节点值和重复节点?

时间:2015-02-05 16:09:49

标签: xml xpath nodes pentaho kettle

我的格式为XML。我在pentaho中使用Get XML来解析它。但我无法获得获得所有价值的正确途径。 我想要“自定义属性”的所有值。

它只给了我第一个属性的价值。仅用于'性'。 任何人都可以帮助我如何获取其他自定义属性的值。

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

在字段标签中按“获取字段”后。我自动在Fields选项卡中获取自定义属性xpath,如下所述: -  它只给出了“性”的价值。

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>

最后我想要一个如下所述的单行: -

firstname lastname   sex    height    weight   dateofbirth   occupation

ABCDEH    JKLAM      male    160        78      09/09/1990    engineer

有人可以帮助我吗

1 个答案:

答案 0 :(得分:5)

我不确定您在代码中做了什么。首先在&#34; 循环XPATH &#34;步骤的设置部分,定义父节点路径而不是自定义属性&#39;路径(如上所述)如下:

/names/name/custom-attributes//*

其次,当您获得字段属性,即&#34; 自定义属性&#34;时,您需要将XPATH指定为&#39; &#39; (点)。这将执行属性值的递归。检查下图:

最后,您将获得递归数据:

我已在here中放置了示例代码。请查看参考资料。

希望有所帮助:)