2013-04-02 24 views
1

我有一個關於從XML xpath獲取數據的查詢。Scriptella:如何處理錯誤,同時通過Xpath從XML中獲取數據

<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的就像你在How to ETL multiple files using Scriptella?描述)

附:對於最後一部分,我是這樣做的

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

其中「input」是不同xml文件名的映射關鍵字。

有人可以幫我嗎?有必要儘快知道我的項目。

+0

我害怕我不跟隨這裏的實際問題。你不能爲你正在處理的每種類型的XML編寫單獨的ETL。因此,在您使用OtherCommCenter XML的示例中,您可以簡單地使用OtherCommCenter/MenuData/Menu/Noun進行查詢。帶有CommunicationCenter/Response/MenuData/Menu/Noun查詢的ETL文件將簡單地忽略在根處沒有的xml。 – ejboy

+0

@ejboy我在一個新的帖子中改寫了這個問題。請考慮一下。 – user1838450

回答

1

這裏是一個人造的例子。假設有一種XML--人和車。

people.xml:

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

Cars.xml:

<cars> 
    <car/> 
</car> 

以下XML運行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>       
相關問題