flunked utopian
flunked utopian

Reputation: 25

How to set element value to xml attribute in esql outputroot

I'm trying to create a xml file, using a compute node. My requirement is to generate the following xml document

   <soapenv:Envelope>
      <soapenv:Body>
         <man:request domain="My-Dom">
            <man:b2b-query-metadata>
               <man:query>
                  <man:query-condition evaluation="property-greater-than">
                     <man:property-name>InputTime</man:property-name>
                     <man:value>2018-08-10 00:00:00</man:value>
                  </man:query-condition>
               </man:query>
               <man:result-constraints>
                  <man:sort-order>
                     <man:property-name direction="asc">InputTime</man:property-name>
                  </man:sort-order>
               </man:result-constraints>
            </man:b2b-query-metadata>
         </man:request>
      </soapenv:Body>
   </soapenv:Envelope>

Following is the snippet that is used to generate the required xml document.

CREATE COMPUTE MODULE FLOW_Compute

       CREATE FUNCTION Main() RETURNS BOOLEAN

       BEGIN
              CALL CopyMessageHeaders();
              CALL CreateSOAPReq();
              RETURN TRUE;
       END;

       CREATE PROCEDURE CopyMessageHeaders() BEGIN

              DECLARE I INTEGER 1;
              DECLARE J INTEGER;
              SET J = CARDINALITY(InputRoot.*[]);

              WHILE I < J DO
                     SET OutputRoot.*[I] = InputRoot.*[I];
                     SET I = I + 1;
              END WHILE;

       END;

              CREATE PROCEDURE CreateSOAPReq() BEGIN       

              DECLARE soapenv NAMESPACE 'http://schemas.xmlsoap.org/soap/envelope/';
              DECLARE man NAMESPACE 'http://www.datapower.com/schemas/management';   

              SET OutputRoot.HTTPRequestHeader.POST = 'https://my.testbox.com:5550/service/mgmt/3.0'; 
              SET OutputRoot.HTTPRequestHeader."Content-Type" = 'text/xml;charset=UTF-8';
              SET OutputRoot.HTTPRequestHeader."Authorization" = 'Basic '||base64Encode(CAST('myuserid:mypassword' as BLOB CCSID InputRoot.Properties.CodedCharSetId));
              SET OutputRoot.HTTPRequestHeader.Host = 'my.testbox.com:5550';

              SET OutputRoot.XMLNSC.soapenv:Envelope.soapenv:Body.man:request.(XMLNSC.Attribute)man:domain = 'My-Dom';
              SET OutputRoot.XMLNSC.soapenv:Envelope.soapenv:Body.man:request.man:"b2b-query-metadata".man:query.man:"query-condition".evaluation = 'property-greater-than';
              SET OutputRoot.XMLNSC.soapenv:Envelope.soapenv:Body.man:request.man:"b2b-query-metadata".man:query.man:"query-condition".man:"property-name" = 'InputTime';
              SET OutputRoot.XMLNSC.soapenv:Envelope.soapenv:Body.man:request.man:"b2b-query-metadata".man:query.man:"query-condition".man:value = '2018-08-10 00:00:00';  
              --SET OutputRoot.XMLNSC.soapenv:Envelope.soapenv:Body.man:request.man:"b2b-query-metadata".man:"result-constraints".man:"sort-order".man:"property-name".(XMLNSC.Attribute)man:direction = 'asc';          
       END;

END MODULE;

Update: after successfully clearing the hurdle where in i was able to obtain the following xml element: <man:request domain="My-Dom"> using the following statement SET OutputRoot.XMLNSC.soapenv:Envelope.soapenv:Body.man:request.(XMLNSC.Attribute)man:domain = 'B2B-Dev'; , I am struck at this part: <man:property-name direction="asc">InputTime</man:property-name>

I tried to scan for examples wherein we create outputroot from scratch, however most of the examples deal with parsing through inbound content: https://www.ibm.com/support/knowledgecenter/en/SSKM8N_8.0.0/com.ibm.etools.mft.doc/ac67241_.htm

I understand that we are having attributes, which need to be assigned element value. I'm not sure on how to proceed on this bit. Can someone point me to an example which involves a the SET command in esql.

Any suggestion is welcome.

Upvotes: 0

Views: 5190

Answers (3)

Sridhara Shastry
Sridhara Shastry

Reputation: 11

Try flipping the assignments.

Assuming below is the XML

<NS1:Envelope xmlns:NS1="http://schemas.xmlsoap.org/soap/envelope/">
   <NS1:Header/>
   <NS1:Body>
      <NS2:request domain="default" xmlns:NS2="http://www.datapower.com/schemas/management">
         <NS2:set-file name="local:///Phase1/tullu">UGlzdGFzaW5naA==</NS2:set-file>
      </NS2:request>
   </NS1:Body>
</NS1:Envelope>

Below is the ESQL

SET OutputRoot.XMLNSC.ns21:Envelope.ns21:Body.ns39:request.(XMLNSC.Attribute)domain = datapowerDomain;
SET OutputRoot.XMLNSC.ns21:Envelope.ns21:Body.ns39:request.ns39:"set-file"=InputRoot.XMLNSC.ns:createFileRequest.directoryDetails.fileContentsInBase64;     
SET OutputRoot.XMLNSC.ns21:Envelope.ns21:Body.ns39:request.ns39:"set-file".(XMLNSC.Attribute)name=targetFQFileName;

Upvotes: 0

flunked utopian
flunked utopian

Reputation: 25

Heres a breakdown for what I've faced so far.

  1. relied solely on Flow exerciser, should have checked the queue content once in a while.
  2. altering OutputRoot.XMLNSC.soapenv:Envelope.soapenv:Body.man:request.(XMLNSC.Attribute)man:domain = 'My-Dom';, resolved and I'm getting outcome as desired when a MQ Output node is placed in front of the Compute node.

Thanks to @Attila Repasi for pointing the flaws, in my esql code. :)

Upvotes: 0

kimbert
kimbert

Reputation: 2422

That's not an ordinary XML attribute - it is a namespace declaration. You need to declare a namespace constant, and then use it in your ESQL as described here:

https://www.ibm.com/support/knowledgecenter/en/SSMKHH_10.0.0/com.ibm.etools.mft.doc/ac67194_.htm

Upvotes: 0

Related Questions