2 Replies Latest reply on Feb 4, 2019 3:47 PM by cormaco

    Stuck with reading XML -- Wrong namespace?

    Marwim

      It seems to be easy to read this XML but somehow I can't get further than '/ns2:ELMAKM/ns2:ELMAKOM' - When I try to read the next element '/ns2:ELMAKM/ns2:ELMAKOM/ELMAVerfahren'

      I get no row

       

      WITH tax AS (

      SELECT XMLTYPE(q'[<?xml version="1.0" encoding="ISO-8859-15" standalone='yes'?>

      <ns2:ELMAKM xmlns:ns6="http://www.itzbund.de/kista/kmkw/01.01"

          xmlns:ns5="http://www.itzbund.de/kista/std/01.01"

          xmlns:ns7="http://www.elster.de/elsterxml/schema/v11"

          xmlns:ns2="http://www.itzbund.de/ELAN/01"

          xmlns:ns4="http://www.itzbund.de/kontenwahrheit/01.00"

          xmlns:ns3="http://www.itzbund.de/kista/km/01.01">

        <ns2:ELMAKOM>

          <ELMAHeader>

            <DatenArt>ELMA_KMRM</DatenArt>

            <ns2:AuthSteuernummer>BZ100281794</ns2:AuthSteuernummer>

            <ns2:AccountID>1006139260</ns2:AccountID>

            <ns2:ErstellungsDatum>2019-01-28T23:14:32.589+01:00</ns2:ErstellungsDatum>

            <ns2:KundeneigeneID>1</ns2:KundeneigeneID>

          </ELMAHeader>

          <ELMAVerfahren>

            <ns6:KISTAKM version="3.0">

              <ns3:KISTA_KM_ANTW OrdBegriff="My Company" UUID="113413ae">

                <ns3:Anfragender_DL Zulassungsnummer="123"/>

                <ns3:Anfragender Zulassungsnummer="234"/>

                <ns3:Antwort xsi:type="ns3:AntwortArt3" KdOrdBegriff="1842757" UUID="113413ae" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

                  <ns3:ReturnCode>01</ns3:ReturnCode>

                  <ns3:Anlass Grund="1" Datum="2019-01-25+01:00"/>

                  <ns3:PersAngabe>

                    <ns3:Person>

                      <ns5:NName>ABC</ns5:NName>

                      <ns5:VName>Ptr</ns5:VName>

                      <ns5:GebDt>1984-05-26</ns5:GebDt>

                    </ns3:Person>

                    <ns3:Adresse xsi:type="ns5:InlandsAdresse">

                      <ns5:Str>Heimat</ns5:Str>

                      <ns5:HausNr>26</ns5:HausNr>

                      <ns5:Ort>MyPlace</ns5:Ort>

                      <ns5:Plz>12345</ns5:Plz>

                    </ns3:Adresse>

                  </ns3:PersAngabe>

                </ns3:Antwort>

              </ns3:KISTA_KM_ANTW>

            </ns6:KISTAKM>

          </ELMAVerfahren>

        </ns2:ELMAKOM>

      </ns2:ELMAKM>]') stx_dokument

      FROM dual

      )

      SELECT  elma.x.getClobVal()

      FROM    tax

             ,XMLTABLE(

                  XMLNAMESPACES(

                       DEFAULT 'http://www.itzbund.de/ELAN/01'

                      ,'http://www.itzbund.de/ELAN/01' AS "ns2"               --war "elan"

                      ,'http://www.itzbund.de/kista/km/01.01' AS "ns3"        --war "elma0"

                      ,'http://www.itzbund.de/kontenwahrheit/01.00' AS "ns4"  --war "kw"

                      ,'http://www.itzbund.de/kista/std/01.01'  AS  "ns5"     --war "k"

                      ,'http://www.itzbund.de/kista/kmkw/01.01'  AS "ns6"     --war "kmkw"

                      ,'http://www.elster.de/elsterxml/schema/v11' AS "ns7"

                      ),

                    '/ns2:ELMAKM/ns2:ELMAKOM'--/ELMAVerfahren'--/ns6:KISTAKM'--/ns3:KISTA_KM_ANTW/ns3:Antwort'

                  PASSING tax.stx_dokument

                  COLUMNS

                  x XMLTYPE PATH '/'

                  ) elma

      Is it because ELMAVerfahren is defined in ns2 but used without a prefix ? - That's why I used the ELAN/01 namespace as default, too.

       

      Regards

      Marcus

        • 1. Re: Stuck with reading XML -- Wrong namespace?
          mNem

          '/ns2:ELMAKM/ns2:ELMAKOM/*:ELMAVerfahren'

          1 person found this helpful
          • 2. Re: Stuck with reading XML -- Wrong namespace?
            cormaco

             

            Is it because ELMAVerfahren is defined in ns2 but used without a prefix ? - That's why I used the ELAN/01 namespace as default, too.

            A tag does not inherit its namespace from a parent. The only indication for the namespace is the prefix or no prefix for the default namespace.

            In your case ELMAVerfahren has no prefix and so belongs to the default namespace, which is empty in your xmlfile.

            However in your xmltable you have defined the default namespace as something not empty and so the tags don't match.

            Remove your definition of the default namespace completely and it works.

            mNems solution works because the "*" matches any namespace

             

            SELECT  elma.x.getClobVal()
            FROM    tax
                   ,XMLTABLE(
                        XMLNAMESPACES(               
                            'http://www.itzbund.de/ELAN/01' AS "ns2"               --war "elan"
                            ,'http://www.itzbund.de/kista/km/01.01' AS "ns3"        --war "elma0"
                            ,'http://www.itzbund.de/kontenwahrheit/01.00' AS "ns4"  --war "kw"
                            ,'http://www.itzbund.de/kista/std/01.01'  AS  "ns5"     --war "k"
                            ,'http://www.itzbund.de/kista/kmkw/01.01'  AS "ns6"     --war "kmkw"
                            ,'http://www.elster.de/elsterxml/schema/v11' AS "ns7"
                            ),
                          '/ns2:ELMAKM/ns2:ELMAKOM/ELMAVerfahren/ns6:KISTAKM/ns3:KISTA_KM_ANTW/ns3:Antwort'
                        PASSING tax.stx_dokument
                        COLUMNS
                        x XMLTYPE PATH '/'
                        ) elma
            
            
            ELMA.X.GETCLOBVAL()                                                             
            --------------------------------------------------------------------------------
            <ns3:Antwort xmlns:ns3="http://www.itzbund.de/kista/km/01.01" xsi:type="ns3:Antw