Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Remove the unnecessary tags in XML using PL/SQL

Arun ThomasMar 15 2015 — edited Mar 15 2015

Hi Friends

from the below XML, its generate by a complex SQL query, Now we need to remove all the object type tags, and all the empty tags.

Version - PL/SQL Release 11.2.0.3.0 - Production

<MajorLine>

    <MAJOR_LINE_OBJECT_TYPE> -- Need to remove these Objects types showing in the XML

        <LINEID>143424538</LINEID>

        <ITEMNAME>TC-ABC-123</ITEMNAME>

        <ITEMPATH>78245</ITEMPATH>

        <QUANTITY>10</QUANTITY>

        <SERVICELINE/> -- Need to remove all the Empty tags

        <MINORLINE>

            <MINOR_LINE_OBJECT_TYPE> -- Need to remove these Objects types showing in the XML

                <LINEID>143424799</LINEID>

                <ITEMNAME>TCC-abc</ITEMNAME>

                <ITEMPATH>78245</ITEMPATH>

                <QUANTITY>10</QUANTITY>

                <SERVICELINE/>-- Need to remove all the Empty tags

                <MINOR_MINOR_LINES>

                    <M_MINOR_LINE_TYPE> -- Need to remove these Objects types showing in the XML

                        <LINEID>143424798</LINEID>

                        <ITEMNAME>SF15-abc-xyz</ITEMNAME>

                        <ITEMPATH>78245</ITEMPATH>

                        <QUANTITY>10</QUANTITY>

                  </M_MINOR_LINE_TYPE>-- Need to remove these Objects types showing in the XML

                </MINOR_MINOR_LINES>

            </MINOR_LINE_OBJECT_TYPE>--Need to remove these Objects types showing in the XML

        </MINORLINE>

    </MAJOR_LINE_OBJECT_TYPE>-- Need to remove these Objects types showing in the XML

</MajorLine>

i tried one of the queries posted in this blog ,PFB  to remove the empty tags , but it didnt work for me unfortunately. Please help.

PFB

WITH sample_data AS (

  SELECT xmltype('<MajorLine>

    <MAJOR_LINE_OBJECT_TYPE>

        <LINEID>143424538</LINEID>

        <ITEMNAME>hijk</ITEMNAME>

        <ITEMPATH>78245</ITEMPATH>

        <QUANTITY>10</QUANTITY>

        <SERVICELINE/>

        <MINORLINE>

            <MINOR_LINE_OBJECT_TYPE>

                <LINEID>143424799</LINEID>

                <ITEMNAME>efg</ITEMNAME>

                <ITEMPATH>78245</ITEMPATH>

                <QUANTITY>10</QUANTITY>

                <SERVICELINE/>

                <MINOR_MINOR_LINES>

                    <M_MINOR_LINE_TYPE>

                        <LINEID>143424798</LINEID>

                        <ITEMNAME>abc</ITEMNAME>

                        <ITEMPATH>78245</ITEMPATH>

                        <QUANTITY>10</QUANTITY>

                    </M_MINOR_LINE_TYPE>

                </MINOR_MINOR_LINES>

            </MINOR_LINE_OBJECT_TYPE>

        </MINORLINE>

    </MAJOR_LINE_OBJECT_TYPE>

</MajorLine>') xmldoc

  FROM dual

)

SELECT deleteXML( t.xmldoc

                , '/MajorLine/*[.="" or contains(.,"?")]'

                ) as result

FROM sample_data t

;

My email ID is sharwitharunthomas@gmail.com -- You can reach me

thanks in advance ... Arun thomas T

This post has been answered by odie_63 on Mar 15 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 12 2015
Added on Mar 15 2015
2 comments
1,808 views