Topic
  • 8 replies
  • Latest Post - ‏2017-01-02T21:10:07Z by kimbetr
Diamond.Li
Diamond.Li
27 Posts

Pinned topic Namespace and Asterisk in XML Field Reference

‏2016-11-25T22:34:22Z |

Hello, 

I have a request message like this: 

<employees xmlns="www.ibm.com">
   <employeefulltime>
      <contact>
      <homephone>123</homephone>
      </contact> 
   </employee>
  <employeeparttime>
      <contact>
      <homephone>456</homephone>
      </contact>
   </employee>
</employees>

I'm using the following code to parse this incoming message: 

        FOR iterator AS InputRoot.XMLNSC.*:employees.*:"employ*"[]  DO
            DECLARE blobEmployee BLOB;
            SET blobEmployee = ASBITSTREAM(iterator OPTIONS FolderBitStream CCSID InputRoot.Properties.CodedCharSetId);
        END FOR;

 

The iterator will be null and couldn't go into FOR loop. 

If I removed namespace from <employees xmlns="www.ibm.com"> and changed it into <employees>, code went into FOR loop and run normally. 

My version is 8.0.0.2. 

Can someone please kindly help why code doesn't work with namespace.

Appreciate!

Diamond

 

 

 

 

  • LuisFelipeBertel
    LuisFelipeBertel
    4 Posts

    Re: Namespace and Asterisk in XML Field Reference

    ‏2016-11-28T12:31:30Z  

    You need to declare the namespace if your using it.
    https://www.ibm.com/support/knowledgecenter/en/SSKM8N_8.0.0/com.ibm.etools.mft.doc/ac67194_.htm

    Then you can use it to traverse the message using it. 


     

    Updated on 2016-11-28T12:32:01Z at 2016-11-28T12:32:01Z by LuisFelipeBertel
  • Diamond.Li
    Diamond.Li
    27 Posts

    Re: Namespace and Asterisk in XML Field Reference

    ‏2016-11-28T14:40:07Z  

       Hi Luis, 

    I have added namespace to my ESQL, result is same. Thanks for your help! 

       DECLARE ibm NAMESPACE 'www.ibm.com';
            
            FOR iterator AS InputRoot.XMLNSC.ibm:employees.ibm:"employ*"[]  DO
                DECLARE blobEmployee BLOB;
                SET blobEmployee = ASBITSTREAM(iterator OPTIONS FolderBitStream CCSID InputRoot.Properties.CodedCharSetId);
                
                DECLARE tempValue CHARACTER;
                SET tempValue = CAST(blobEmployee AS CHARACTER CCSID 1208);
                
                
            END FOR;
        
    Also, I correct typos in request message. Here is the right one: 
    <employees xmlns="www.ibm.com">
       <employeefulltime>
          <contact>
          <homephone>123</homephone>
          </contact> 
       </employeefulltime>
      <employeeparttime>
          <contact>
          <homephone>456</homephone>
          </contact>
       </employeeparttime>
    </employees>

    Updated on 2016-12-01T16:31:07Z at 2016-12-01T16:31:07Z by Diamond.Li
  • Diamond.Li
    Diamond.Li
    27 Posts

    Re: Namespace and Asterisk in XML Field Reference

    ‏2016-11-30T14:24:50Z  

    Can someone please kindly help? It's blocking my project. Thanks!

     

  • Diamond.Li
    Diamond.Li
    27 Posts

    Re: Namespace and Asterisk in XML Field Reference

    ‏2016-12-09T18:22:42Z  

    Would someone kindly help?  Appreciate!

  • fjb_saper
    fjb_saper
    159 Posts

    Re: Namespace and Asterisk in XML Field Reference

    ‏2016-12-12T14:31:59Z  

    If you want to use the namespace dynamically i.e. keep the "*" you must declare a Reference and set it to the value down the tree.

    As to iterate over multiple namespaces for these values ... iterate over the siblings with same Name... and look at what that does.

    Remember we cannot guess your full message tree ... so your mileage will vary....

  • Diamond.Li
    Diamond.Li
    27 Posts

    Re: Namespace and Asterisk in XML Field Reference

    ‏2016-12-12T15:25:36Z  

    Hi Fjb, 

    I'm not sure I understand your answer correctly. From my post on Nov 28, I didn't use dynamic namespace: 

            DECLARE ibm NAMESPACE 'www.ibm.com';
            
            FOR iterator AS InputRoot.XMLNSC.ibm:employees.ibm:"employ*"[]  DO
                DECLARE blobEmployee BLOB;
                SET blobEmployee = ASBITSTREAM(iterator OPTIONS FolderBitStream CCSID InputRoot.Properties.CodedCharSetId);
                
                DECLARE tempValue CHARACTER;
                SET tempValue = CAST(blobEmployee AS CHARACTER CCSID 1208);
                
                
            END FOR;

    Would you like to show me ESQL code how to handle this case?

     

    Appreciate for your help!

     

     

  • SupriyoDebnath
    SupriyoDebnath
    27 Posts

    Re: Namespace and Asterisk in XML Field Reference

    ‏2016-12-13T15:23:15Z  

    Hi Daimond.Li

    Are you sure the XML field reference with asterisk in the end is working even without namespace??? I see it is not when I run it in IIB 10.0.0.7. Of course, asterisk works as a wildcard but in this case, its a NO. You should find some other way.

  • kimbetr
    kimbetr
    3 Posts

    Re: Namespace and Asterisk in XML Field Reference

    ‏2017-01-02T21:10:07Z  

    This is not a namespace issue. It is caused by the 'employ*'. That is not a valid ESQL field reference.

    You should replace it with * and test the name of the field using the FIELDNAME function and the STARTSWITH function.