Forum Stats

  • 3,872,915 Users
  • 2,266,490 Discussions
  • 7,911,382 Comments

Discussions

How to get EXTRACT to work with xmlns

User_WSY9T
User_WSY9T Member Posts: 2 Green Ribbon
edited Aug 26, 2022 3:04PM in PL/SQL XML Programming


Above works, below (adding xmlns) doesn't... Thanks for helping!


Tagged:

Answers

  • User_WSY9T
    User_WSY9T Member Posts: 2 Green Ribbon
    edited Aug 26, 2022 3:13PM

       I changed EXTRACT(blah) to be EXTRACT(blah, namespace) and it worked. Thanks


  • cormaco
    cormaco Member Posts: 2,037 Silver Crown

    EXTRACT is deprecated, you should use XMLQUERY or XMLTABLE these days:

    Here are examples with your data:

    select
        xmlcast(
            xmlquery(
                'declare default element namespace "http://xmlns.blah.com/srsedd/pricing";
                /implementPricingEvent/messageVersion' passing
                xmltype(
                    '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                    <implementPricingEvent xmlns="http://xmlns.blah.com/srsedd/pricing">
                        <messageVersion>2.3.1</messageVersion>
                    </implementPricingEvent>'
                )
                returning content
            )
            as varchar2(10)
        ) as version
    from dual;
    
    VERSION   
    ----------
    2.3.1
    
    select version
    from xmltable(
        xmlnamespaces(default 'http://xmlns.blah.com/srsedd/pricing' ),
        '/implementPricingEvent/messageVersion' passing
            xmltype(
                '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                <implementPricingEvent xmlns="http://xmlns.blah.com/srsedd/pricing">
                    <messageVersion>2.3.1</messageVersion>
                </implementPricingEvent>'
            )
            columns
                version varchar2(10) path '.'
    );
    
    
    VERSION   
    ----------
    2.3.1