This topic contains 1 reply, has 2 voices, and was last updated by  Casey Trauer 4 years, 6 months ago.

Removing empty nodes in XML

  • Hi,
    I have a XML message
    XMLMsg = <rosters>
    <roster>
    <id> 1</id>
    <employeeCode> </employeeCode>
    <courtDate> 2012-12-03 </courtDate>

    </roster>
    <roster>
    <id> 2</id>
    <employeeCode> we3567</employeeCode>
    <courtDate> 2012-12-03 </courtDate>

    </roster>

    <roster>
    <id> 3</id>
    <employeeCode> we3567</employeeCode>
    <courtDate> </courtDate>

    </roster>
    </rosters>

    I have validated each element for a standard format and I am accumulating the errors in a table. We have multiple roster inside rosters. After validating, I need to remove the child which doesnot conforms to the standard and process remaining IDs to the destination.
    Here is the content of error1 table
    Employeecode is not present for Id (1)
    Courtdate is not present for Id (3)

    error2 table.
    1
    3

    So I need to remove the roster with Id 1 and 3 alone and process ID 2. I can achieve this by using node:remove(), but I am not sure how to specify which element to remove.
    Any inputs much appreciated.

    Hello,

    The following code will remove the first roster node under the rosters parent:

    xml.rosters:remove(1)

    So as you iterate through those roster records, store those node indexes of invalid records in a separate table and then create a separate process/function for removing the nodes afterward.

    Casey Trauer,
    Director, Client Education
    iNTERFACEWARE

You must be logged in to reply to this topic.