3 Replies Latest reply: Nov 2, 2012 3:53 AM by odie_63 RSS

    APPENDCHILDXML with namespace_string

    952738
      (10gR2)

      Having issues with a simple append child. I suspect the issue is the namespace but I have declared using namespace_string.

      The output I'm expecting should be:

      <?xml version="1.0" encoding="ISO-8859-1"?>
      <ers:OPS xmlns:ers="http://www.test.com/schema/ers/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.test.com/schema/ers/v3">
      <ers:LOG xmlns:ers="http://www.test.com/schema/ers/v3" TEST="TESTVAL" >
      </ers:LOG>
      </ers:OPS>

      However, the LOG child element is not being added.

      Script is:

      Declare

      v_xmltmp XMLTYPE;

      Begin

      Select Appendchildxml(Xmltype('<?xml version="1.0" encoding="ISO-8859-1"?><ers:OPS xmlns:ers="http://www.test.com/schema/ers/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.test.com/schema/ers/v3"></ers:OPS>')
      ,'/OPS'
      ,Xmltype('<ers:LOG xmlns:ers="http://www.test.com/schema/ers/v3" TEST="TESTVAL" ></ers:LOG>'),'xmlns:ers="http://www.test.com/schema/ers/v3"')
      Into V_Xmltmp
      From Dual d;

      dbms_output.put_line(XML: '||v_xmltmp.getclobval());

      END;
        • 1. Re: APPENDCHILDXML with namespace_string
          odie_63
          I suspect the issue is the namespace but I have declared using namespace_string.
          You have declared the namespace mapping, yes. However you're not using it in the XPath expression '/OPS' :
          SQL> Declare
            2  
            3  v_xmltmp XMLTYPE;
            4  
            5  Begin
            6  
            7  Select Appendchildxml(
            8           Xmltype('<?xml version="1.0" encoding="ISO-8859-1"?>
            9                     <ers:OPS xmlns:ers="http://www.test.com/schema/ers/v3"
           10                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           11                              xsi:schemaLocation="http://www.test.com/schema/ers/v3">
           12                     </ers:OPS>')
           13         , '/ers:OPS'
           14         , Xmltype('<ers:LOG xmlns:ers="http://www.test.com/schema/ers/v3" TEST="TESTVAL" ></ers:LOG>')
           15         , 'xmlns:ers="http://www.test.com/schema/ers/v3"'
           16         )
           17  Into V_Xmltmp
           18  From Dual d;
           19  
           20  dbms_output.put_line('XML: '||v_xmltmp.getclobval());
           21  
           22  END;
           23  /
           
          XML: <?xml version="1.0" encoding="UTF-8"?><ers:OPS xmlns:ers="http://www.test.com/schema/ers/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.test.com/schema/ers/v3">
                             <ers:LOG xmlns:ers="http://www.test.com/schema/ers/v3" TEST="TESTVAL"/></ers:OPS>
           
          PL/SQL procedure successfully completed
           
          • 2. Re: APPENDCHILDXML with namespace_string
            952738
            Ahhh - I see. Thank you - again.

            Seems counter intuitive (to a novice at least) that you need to include for appendchildxml XPATHs but not in an extractvalue XPATH.
            • 3. Re: APPENDCHILDXML with namespace_string
              odie_63
              Seems counter intuitive (to a novice at least) that you need to include for appendchildxml XPATHs but not in an extractvalue XPATH.
              Not sure what you mean.

              Could you give an example with extractValue where the document has a namespace but you don't need to include it in the QName?

              I know we can do it when the table is schema-based, is that what you mean?