2015-02-05 153 views
0

我有一个XML在下面提到的格式。我在pentaho中使用Get XML来解析这个问题。但我无法获得正确的路径来获取所有的值。 我想要'自定义属性'的所有值。如何提取pentaho中的XML节点值和循环节点?

它只给我只有'性'的第一个属性.i.e的值。 任何人都可以请帮助我如何获得其他定制属性的值。

我已经给出了 'LoopXpath' 为设置: - /names/name

按下后 '获取领域' 在领域选项卡,。我会自动在Fields选项卡中获取自定义属性xpath,如下所述: - 它只给出'sex'的值。

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

XPath本身是正确的。显示你如何使用它。 – Tomalak 2015-02-05 16:13:55

回答

5

我不知道你已经在你的代码做了什么。首先,在步骤“环路XPATH”设置部分,限定父节点的路径,而不是“定制属性”路径(如你所提到的)如下:

/names/name/custom-attributes//* 

其次,当您获取字段属性,即“自定义属性”时,您需要指定XPATH为''(点)。这将执行属性值的递归。检查下面的图片:

最后,你会得到的递归数据为:

我挂了一个示例代码here。请检查它的参考。

希望它有帮助:)

+1

很好的答案。我试图解决这个问题,但没有运气。我终于尝试使用这一步“XML输入流(StAX)” – 2015-02-05 18:29:42

+0

@MarlonAbeykoon谢谢;)...是的“XML输入流(StAX)”也是一个不错的选择。但是选择取决于数据量。与我上面的答案相比,StAX会在数据量巨大的情况下扩大规模。我假设你所需要做的就是在StAX输入步骤后过滤出所需的属性。 – Rishu 2015-02-05 19:12:25

+0

@ Rhishu是的,我读过它。我已经在Pentaho上提出了两个问题,但似乎Pentaho社区在这里是非常低的stackoverflow。请看看他们,如果你有时间:) – 2015-02-06 06:24:37