Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

checking for absent elements

Help
Lou
2008-11-20
2013-03-03
  • Lou
    Lou
    2008-11-20

    Can someone explain what is the proper way to check for absent elements.  Given the following snippet:

    Difference diff = (Difference)iter.next();
    NodeDetail ndSrc = diff.getControlNodeDetail();
    NodeDetail ndTst = diff.getTestNodeDetail();
    String sname = "?";
    String srcVal = "?";
    String dname = "?";
    String tstVal = "?";
               
    String ndSrcVal = ndSrc.getValue();
    String ndTstVal = ndTst.getValue();

    I was using the values returned from the getValue() calls to check for the string "null" and then classify the change as insert, update or delete.  For example, if the control/src value is null, but the test value is not, then it must be an add.

    So, given the following XML fragment:

    CONTROL
    <dummyroot/>

    TEST
    <dummyroot>
    <order_conditions>
    <condition_code>ABC</condition_code>
    </order_conditions>
    </dummyroot>

    I'm getting the following results:

    control value returned:  false
    test value returned:  true

    I could swear this was returning the string "null" - could it be related to the qualifier I am using?  What should I expect from these calls when the nodes are absent?