1

我有一个关于从 XML xpath 获取数据的查询。

 <query connection-id="in">
    CommunicationCenter/Response/MenuData/Menu/Noun
<!--something I have to do inside script using the data fetched from xpath-->
</query>

我的问题是 - 假设 1 个 XML 没有这种 Xpath 结构。它具有“OtherCommCenter/MenuData/Menu/Noun”或其他结构。然后,当我运行作业时,它说作业没有例外地执行,因为它没有从 xpath 获得任何值,所以什么也没发生。意味着它返回null。那么,我该如何捕捉那里的错误呢?我必须知道 xpath 中的哪个元素会产生问题,或者如果这不可能,至少是哪个 xml 在结构中产生了这个错误?

因为在我的项目中,我必须处理多个 XML,我通过将作业提交给 ExecutorService 来做到这一点,就像您在如何使用 Scriptella 的 ETL 多个文件中描述的那样?

PS最后一部分,我是这样做的

<connection id="in" driver="xpath" url="$input"/>

其中“input”是不同 xml 文件名的映射键。

有谁能够帮助我?有必要尽快了解我的项目。

4

1 回答 1

1

这是一个人为的例子。假设有某种 XML - 人和汽车。

人.xml:

<people>
    <person></person>
</people>

汽车.xml:

<cars>
    <car/>
</car>

以下 xml 对 /people/person 和 /cars/car 运行 2 次查询,并在至少找到一条记录时设置全局标志:

<etl>
    <connection driver="jexl" id="jexl"/>
    <connection driver="xpath" id="xpath" url="input.xml"/>
    <connection id="log" driver="text"/>

    <query connection-id="xpath">
        /people/person
        <script connection-id="jexl">
            # set flag to true if at least one element was found
            etl.globals['people']=true;
        </script>
    </query>
    <script connection-id="log" if="!etl.globals['people']">
        WARNING: No people found in the XML file
    </script>

    <query connection-id="xpath">
        /cars/car
        <script connection-id="jexl">
            etl.globals['cars']=true;
        </script>
    </query>

    <script connection-id="log" if="!etl.globals['cars']">
        WARNING: No cars found in the XML file
    </script>
</etl>                          
于 2013-04-02T14:06:24.933 回答