ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

data-into xml file with datasubf not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • data-into xml file with datasubf not working

    Hello,

    I've a problem with the use of data-into in combination with the keyword datasubf.

    E.g. my xml contains the following:

    <Order>
    <OrderID schemeID="REF">266108</OrderID>
    <OrderStatusCode>104</OrderStatusCode>
    <Remark>
    <TextFunctionTypeCode>107</TextFunctionTypeCode>
    <TextLines>blablabla</TextLines>
    </Remark>
    </Order>


    There is a webservices which calls my RPG-program. We are on V7R3.

    If I use the data-into everything works except the following statement:

    <OrderID schemeID="REF">266108</OrderID>

    The data-into contains the following (I use the PROFOUND 3th party solutions as PARSER):

    DATA-INTO dataDs
    %DATA(' ': 'case=convert allowmissing=yes countprefix=num_ path=Order +
    allowextra=yes datasubf=value')
    %PARSER( 'PUIUDFINTO'
    : '{ +
    "value_true": "true", +
    "value_false": "false", +
    "document_name": "dataDs" +
    }')
    ;


    The reason it doesn't work looks like there is a conflict with the ds-name OrderID and the extra 'schemeID' in it.

    My DS looks like:

    dcl-ds dataDs qualified inz;
    dcl-ds OrderID ;
    value varchar(50);
    End-DS;
    OrderStatusCode char(3);
    dcl-ds Remark ;
    TextFunctionTypeCode char(3);
    TextLines char(500);
    END-DS;

    end-ds;​​
    I'v tried several solutions but nothing helps.
    Everytime I get 'REF' in my value.

    Is there somebody who can help?

    Kind regards,

  • #2
    I have to ask. Why are you not using XML-INTO? That was what datasubf was introduced for. In fact I'm a little surprised that DATA-INTO supports it. Are you sure your parser supports it?

    P.S. You need a subfield called SchemeId as well as the value one in the OrderId DS. That may be causing confusion for your parser but since I have no idea where that parser comes from or why you aren't using XML-INTO I can't tell for sure.
    Last edited by JonBoy; January 11, 2023, 08:05 AM.

    Comment


    • #3
      Hello,
      I don't use xml-into because the file comes as a parameter via the webservice in my program. (So it isn't first placed at the IFS). Therefore xml-into isn't working.
      You can use datasubf either for data-into, see datasubf - IBM Documentation.

      I also have tried adding the schemeID as subfield, but that didn't help...

      Kind regards.​

      Comment


      • #4
        There is no difference between XML-INTO and DATA-INTO in this regard. XML-INTO only processes a file if you use the option doc-file. Without it, it expects the XML to be contained in the named variable.

        So for your example, you would take the data from the web service (I called it XMLData) and then the XML-INTO should be:
        Code:
        XML-INTO dataDs
        %XML( XMLData : 'case=convert allowmissing=yes countprefix=num_ allowextra=yes datasubf=value');
        Also unless you really need it you should try to avoid allowmissing=yes when possible.

        Comment


        • #5
          This example of XML-INTO works and retrieves both components. I omitted allowmissing etc. since it wasn't needed in this case.
          Code:
          **free
          dcl-s wait char(1);
          dcl-s XMLData varchar(1000)
          inz('<Order>-
          <OrderID schemeID="REF">266108</OrderID>-
          <OrderStatusCode>104</OrderStatusCode>-
          <Remark>-
          <TextFunctionTypeCode>107</TextFunctionTypeCode>-
          <TextLines>blablabla</TextLines>-
          </Remark>-
          </Order>');
          dcl-ds Order qualified inz;
             dcl-ds OrderID ;
                value varchar(50);
                schemeID char(3);
             end-DS;
             OrderStatusCode char(3);
             dcl-ds Remark ;
                TextFunctionTypeCode char(3);
                TextLines char(500);
             end-ds;
          end-ds;
          
          XML-INTO Order
          %XML( XMLData : 'case=convert datasubf=value');
          dsply ( 'For ID: ' + Order.OrderId.schemeID + ' the value is:');
          dsply ( Order.OrderId.value );
          dsply ( 'Check results' ) ' ' wait;
          *inlr = *on;​
          If for some reason you are forced to use your own parser with DATA-INTO then I can only suspect that there is a bug in it and it is not able to handle the datasubf situation.

          Comment


          • #6
            Hi Jon,
            Thank you for your investigations and tips.
            Your example works fine for me, but due to the PARSER I'm not allowed to use the xml-into.
            So your last suggestion was the golden tip: I had to use the 'datasubf' in the PARSER itself (so I was the 'bug';-))

            DATA-INTO dataDs
            %DATA(' ': 'case=convert allowmissing=yes countprefix=num_ path=Order +
            allowextra=yes ')​
            %PARSER( 'PUIUDFINTO'
            : '{ +
            "value_true": "true", +
            "value_false": "false", +
            "document_name": "dataDs", +
            "datasubf": "value" +
            }')

            and that worked!!!!!

            FYI: Because not all fields in the xmlfile are obligatory I use 'allowmissing=yes'.

            Kind regards.​

            Comment


            • #7
              Glad to hear you resolved it. Two points:

              1: countprefix is not limited to arrays. You can also use it for individual elements and test the value (zero or 1) to determine whether it was present. that way you can omit allowmissing=yes which will protect you from unexpected changes in the XML.

              2: It appears that the web service is being invoked by the parser under the covers - that is a really weird way to do it. This seems a very inflexible design. And, as you have already seen, it forces you to duplicate the options with the resulting possibility of error. It is also masking the origin of the data - too much of a black box. Not to mention having to write an XML parser when RPG already supplies one. Just weird.

              Comment

              Working...
              X