title: Walk trough xmlnsc tree and remove namespaces in ESQL
body: <p><strong>EDIT:</strong> By removing xmlns I tried to solve a problem when Mapping Node wouldn't parse Input Message with fields that contain namespace. Input Body is set manually - not from XSD. When namespaces are removed from file manually everything works. But when I do use ESQL script it stops working for some uknown to me reason.</p>
  
  <p>Hello I have XML message from which I need to remove namespaces. What I am trying to do is recursively walk trough XML tree and remove xmlns attribute if exists. Unfortunatelly when I'm trying to do <code>SET element = NULL</code> my loop won't go to the next element <code>MOVE element NEXTSIBLING</code>. I tried to do <code>DELETE FIELD element</code> but that gives same effect.</p>
  
  <p>Here's my full code:</p>
  
  <pre><code>CREATE COMPUTE MODULE test_Compute1
  CREATE FUNCTION Main() RETURNS BOOLEAN
  BEGIN
       DECLARE blobMsg BLOB Environment.BLOB.BLOB ;
       CREATE LASTCHILD OF Environment.Variables.inpMsg DOMAIN ('XMLNSC') NAME 'XMLNSC';
       CREATE LASTCHILD OF Environment.Variables.inpMsg.XMLNSC PARSE(blobMsg OPTIONS FolderBitStream CCSID InputRoot.Properties.CodedCharSetId FORMAT 'XMLNSC');
       SET Environment.Variables.statusRes.statusCode = Environment.Variables.inpMsg.XMLNSC.errorResponse.httpCode;
       SET Environment.Variables.statusRes.detail = Environment.Variables.inpMsg.XMLNSC.errorResponse.httpMessage;
       SET Environment.Variables.statusRes.additionalStatus.detail = Environment.Variables.inpMsg.XMLNSC.errorResponse.moreInformation;
       CALL NavigateTree(Environment.Variables.inpMsg.XMLNSC);
      RETURN TRUE;
  END;
  
  CREATE PROCEDURE NavigateTree(IN root REFERENCE)
  BEGIN
      DECLARE element REFERENCE TO root;
      DECLARE hint CHARACTER;
      DECLARE test CHARACTER;
      SET test = '';
      SET hint = '';
  
      MOVE element FIRSTCHILD;
          -----------
      IF LASTMOVE(element) THEN
          SET hint = 'has children';
      ELSE
      IF FIELDNAME(element) = 'xmlns' THEN
          DELETE FIELD element;
      END IF;
      END IF;
  
      WHILE LASTMOVE(element) DO
          -- not working awell:
          -- DECLARE space1 NAMESPACE 'namespace1';
          -- SET element.(XML.NamespaceDecl)* = NULL;
          DECLARE nameField2 CHARACTER FIELDNAMESPACE(element);
          DECLARE nameField CHARACTER FIELDNAME(element);
          DECLARE ifhint CHARACTER;
  
          CALL NavigateTree(element);
          MOVE element NEXTSIBLING;
      END WHILE;
      SET hint = 'finished';
  
  END;
     END MODULE;
  </code></pre>
  
  <p>Do you have any ideas how can I do that?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>CREATE COMPUTE MODULE test_Compute1
      CREATE FUNCTION Main() RETURNS BOOLEAN
      BEGIN
           DECLARE blobMsg BLOB Environment.BLOB.BLOB ;
           CREATE LASTCHILD OF Environment.Variables.inpMsg DOMAIN ('XMLNSC') NAME 'XMLNSC';
           CREATE LASTCHILD OF Environment.Variables.inpMsg.XMLNSC PARSE(blobMsg OPTIONS FolderBitStream CCSID InputRoot.Properties.CodedCharSetId FORMAT 'XMLNSC');
           SET Environment.Variables.statusRes.statusCode = Environment.Variables.inpMsg.XMLNSC.errorResponse.httpCode;
           SET Environment.Variables.statusRes.detail = Environment.Variables.inpMsg.XMLNSC.errorResponse.httpMessage;
           SET Environment.Variables.statusRes.additionalStatus.detail = Environment.Variables.inpMsg.XMLNSC.errorResponse.moreInformation;
           CALL StripNamespaces(Environment.Variables.inpMsg);
          RETURN TRUE;
      END;
      CREATE PROCEDURE StripNamespaces(IN fieldRef REFERENCE)
      BEGIN
          IF FIELDTYPE(fieldRef) IN (XMLNSC.NamespaceDecl, XMLNSC.SingleNamespaceDecl) THEN
              DELETE FIELD fieldRef;
              RETURN;
          END IF;
          DECLARE childRef REFERENCE TO fieldRef;
          MOVE childRef FIRSTCHILD;
          WHILE LASTMOVE(childRef) DO
              DECLARE currentChildRef REFERENCE TO childRef;
              MOVE childRef NEXTSIBLING;
              CALL StripNamespaces(currentChildRef);
          END WHILE;
      END;
  END MODULE;
  </code></pre>
  
  <p>XML that is working as an input file that goes to mapping node (manually edited):</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Receive &gt;
      &lt;messageData&gt;
          &lt;CD &gt;
              &lt;EXP  /&gt;
              &lt;EXAMPLE  /&gt;
          &lt;/CD&gt;
          &lt;XRP &gt;
              &lt;EX1&gt;
                  &lt;SEG&gt;string&lt;/SEG&gt;
                  &lt;SEG2&gt;integer&lt;/SEG2&gt;
              &lt;/EX1&gt;
              &lt;ARRAY&gt;
                  &lt;AR1&gt;string&lt;/AR1&gt;
                  &lt;AR2 /&gt;
              &lt;/ARRAY&gt;
              &lt;ARRAY&gt;
                  &lt;AR1&gt;integer&lt;/AR1&gt;
                  &lt;AR2 /&gt;
              &lt;/ARRAY&gt;
          &lt;/XRP&gt;
      &lt;/messageData&gt;
  &lt;/Receive&gt;
  </code></pre>
  
  <p>XML that is not working (mapping node can't process it properly after it goes trough parsing mentioned above):</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Receive xmlns="namespace"&gt;
      &lt;messageData&gt;
          &lt;CD xmlns="namespace2"&gt;
              &lt;EXP xmlns="namespace3" /&gt;
              &lt;EXAMPLE xmlns="namespace3" /&gt;
          &lt;/CD&gt;
          &lt;XRP xmlns="namespace2"&gt;
              &lt;EX1&gt;
                  &lt;SEG&gt;string&lt;/SEG&gt;
                  &lt;SEG2&gt;integer&lt;/SEG2&gt;
              &lt;/EX1&gt;
              &lt;ARRAY&gt;
                  &lt;AR1&gt;string&lt;/AR1&gt;
                  &lt;AR2 /&gt;
              &lt;/ARRAY&gt;
              &lt;ARRAY&gt;
                  &lt;AR1&gt;integer&lt;/AR1&gt;
                  &lt;AR2 /&gt;
              &lt;/ARRAY&gt;
          &lt;/XRP&gt;
      &lt;/messageData&gt;
  &lt;/Receive&gt;
  </code></pre>
  
  <p>In both cases debugger shows same tree structure after going trough same parser:</p>
  
  <pre><code>Variables
              inpMsg
                      XMLNSC
                              Receive
                                      messageData
                                              CD
                                                      EXP
                                                      EXAMPLE
                                              XRP
                                                      EX1
                                                              SEG:CHARACTER:string
                                                              SEG2:CHARACTER:integer
                                                      ARRAY
                                                              AR1:CHARACTER:string
                                                              AR2
                                                      ARRAY
                                                              AR1:CHARACTER:integer
                                                              AR2
  </code></pre>