CloverETL is now CloverDX - Learn Why

How to check the existence of XML attributes and elements

How-to(s), solutions to common problems, pearls of wisdom

Posts: 1
Joined: Mon Feb 23, 2009 4:10 pm

How to check the existence of XML attributes and elements

Postby csochor » Fri Mar 13, 2009 6:50 pm

It is possible to create graph, that read XML and check for existence of some attribute or element? Attribute may or may not have a value, it could be ssd=”” or ssd=”vvvv”.

Yes. You may use XPath functions in the mapping xpath attribute. Function "empty()" is useful in this scenario.

Example input xml:

Code: Select all


        <name ssd="dd">
        <name ssd="">


Example mapping:

Code: Select all

<Context xpath="/employees/employee" outPort="0">
        <Mapping xpath="empID" cloverField="empID"/>
        <Mapping xpath="name/firstname" cloverField="firstname"/>
        <Mapping xpath="name/surname" cloverField="surname"/>
        <Mapping xpath="not(empty(name/@ssd))" cloverField="ssdAttributeExists"/>
        <Mapping xpath="not(empty(ShieldedRecordNotification))" cloverField="ShieldedRecordNotificationElementExists"/>

Example result:

Code: Select all