webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

how to drop empty or blank fields

  • 1.  how to drop empty or blank fields

    Posted Mon June 06, 2011 07:52 AM

    lets say i have an xml document called doc1, like so -

    abc

    next, i map doc1 to doc2.

    abc

    now, i wish to drop all empty or blank fields from doc2.
    this would be my final intended result -

    abc

    what is the best way to achieve this ?

    i should add that i have set string1 and string2 as Required=False and Allow Null=True.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 2.  RE: how to drop empty or blank fields

    Posted Mon June 06, 2011 02:21 PM

    i used XSLT to read XML and drop all empty / null fields.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 3.  RE: how to drop empty or blank fields

    Posted Mon June 06, 2011 02:26 PM

    I would map only when not null. That way, the tag would not get generated in the first place


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 4.  RE: how to drop empty or blank fields

    Posted Tue June 07, 2011 04:27 AM

    i could also use a regex to remove all instances of empty strings.
    but would this have a performance hit for large strings ?


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 5.  RE: how to drop empty or blank fields

    Posted Tue June 07, 2011 04:23 PM

    sootienann,

    I would stay away from doing regex and pulling out empty tags, post facto.

    If you do a null check before mapping, you wouldnt have to pull the empty tags out later.

    • Hara

    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 6.  RE: how to drop empty or blank fields

    Posted Wed June 08, 2011 02:38 PM

    There is a service removeNullFields in the PSUtilites package, use that to remove the null fields from a doc.

    Make sure you make a local copy of this service and include it in your test plan before you start using it, as the use of the PSUtilites services directly in prod is not recommended.

    Cheers,
    Akshith


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 7.  RE: how to drop empty or blank fields

    Posted Mon June 20, 2011 07:42 PM

    hi dear sootienann …the easy way is that after getting result field with null fields again get map step for the flow and just drop null fields in pipeline output field .thanking you …


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 8.  RE: how to drop empty or blank fields

    Posted Tue June 21, 2011 05:07 PM

    Drop null won’t pull out strings with empty values will it? ex: “ ” is what I would consider an ‘empty’ string.
    When I tried using a $null branch it would remove cases such as
    this → "
    but not → “ ”
    In which case I ended up using a regex pattern to remove all strings with values \r\n\t\s (return, newline, tab, space). Does the flow service removeNullFields in PSUtilities handle both cases above?


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 9.  RE: how to drop empty or blank fields

    Posted Tue June 21, 2011 07:28 PM

    removeNullFields is a Java service in the PSUtilities and yes it will handle the white spaces in the input string. Make sure you set the trimFields to true, this will remove the spaces.

    Cheers,
    Akshith


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 10.  RE: how to drop empty or blank fields

    Posted Wed June 22, 2011 10:01 AM

    can XSLT be used if i want to drop only optional fields which are empty?
    because if i drop all empty fields, then validation will fail if mandatory fields are not present.

    ideally, i am looking for a single function to drop all fields which :

    1. have the attribute Required=False
    2. are empty

    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 11.  RE: how to drop empty or blank fields

    Posted Wed June 22, 2011 04:49 PM

    Okay, that will make things easier from here on. Thanks for the info.

    Marcus


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 12.  RE: how to drop empty or blank fields

    Posted Thu June 23, 2011 04:28 AM

    can XSLT be used if i want to drop only optional fields which are empty?
    because if i drop all empty fields, then validation will fail if mandatory fields are not present.

    ideally, i am looking for a single function to drop all fields which :

    1. have the attribute Required=False
    2. are empty

    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 13.  RE: how to drop empty or blank fields

    Posted Fri February 01, 2019 03:23 AM

    Try below xslt. It will remove all null fields from schema.

    
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="node()|@*">
    <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="*[not(descendant::text()[normalize-space()])]"/>
    </xsl:stylesheet>

    removeNullFields.xslt (428 Bytes)


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services