【问题标题】:Pentaho Data Integration (Spoon) Import XML with nested elementsPentaho Data Integration (Spoon) 使用嵌套元素导入 XML
【发布时间】:2021-02-23 13:14:08
【问题描述】:

我有以下 xml 数据结构,我正在尝试在 Pentaho 中创建一个转换,以提供链接图像中显示的输出。数据中有嵌套在元素中的元素,我似乎只能设置 Loop XPath 选项来获取 main_components 或 sub_components。

<?xml version="1.0" encoding="UTF-8"?>
<components>
    <main_component>
        <name>Engine</name>
        <ref_no>336820-182</ref_no>
        <oem>Ford</oem>
    </main_component>
    <main_component>
        <name>Gearbox</name>
        <ref_no>378912-009</ref_no>
        <oem>GM</oem>
    </main_component>
    <main_component>
        <name>Fuel Tank</name>
        <ref_no>378927</ref_no>
        <oem>GM</oem>
        <sub_component>
            <name>Fuel Pump</name>
            <ref_no>27182A</ref_no>
            <oem>Lucus</oem>
        </sub_component>
            <name>Contents Unit</name>
            <ref_no>1219290</ref_no>
            <oem>Honeywell</oem>
        </sub_component>
    </main_component>
</components>

Required Transformation Output

【问题讨论】:

    标签: xml xpath pentaho kettle spoon


    【解决方案1】:

    您需要使用“XML Input Stream”并且需要编写小的javascript代码来获取父节点信息。 (如果父节点可用,我在这里设置变量,如果子节点可用,则读取这些变量作为该子节点的父信息)

    //Script here
    var pName=null;
    var pRef=null;
    var pOem=null;
    
    
    if( xml_path_level2 != null){
      pName = getVariable("VName","");
      pRef = getVariable("VRef","");
      pOem = getVariable("VOem","");
    }
    else{
      setVariable( "VName",Name,"s");
      setVariable( "VRef",Ref_no,"s");
      setVariable( "VOem",Oem,"s");
    }

    你可以从Here找到样本

    请告诉我你是否可以。

    【讨论】:

    • 这正是我解决问题所需的答案。感谢您花时间为我详细介绍解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多