I have been reading this thread and working on several xml web services. Guess what I found one that I don't know how to do.

This is a sample of the XML
<GetConsumerHoldsResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance"; xmlns="http://services.xxxxxxxxxxx.com/xxx/datacontract/v1.0";>
<Holds>
<Hold>
<Type>Account</Type>
<Process>Plan Year Initialization</Process>
<SuspendedFunctions xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays";>
<d4p1:string>Deposit</d4p1:string>
<d4p1:string>Withdrawal</d4p1:string>
</SuspendedFunctions>
<CreatedBy>Support User (CNBBP\ev1support00294)</CreatedBy>
<CreateDate>2019-04-26T00:00:00</CreateDate>
<ReleaseDate>2019-04-26T00:00:00</ReleaseDate>
</Hold>
<Hold>
<Type>Account</Type>
<Process>Agreements</Process>
<SuspendedFunctions xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays";>
<d4p1:string>Withdrawal</d4p1:string>
</SuspendedFunctions>
<CreatedBy>Support User (CNBBP\ev1support00294)</CreatedBy>
<CreateDate>2019-04-26T00:00:00</CreateDate>
<ReleaseDate>2019-04-26T00:00:00</ReleaseDate>
</Hold>
</Holds>
<MessageId>2019-07-15-16.46.06.397000</MessageId>
<OperationResult>
<ExecutionMessages />
<OperationSucceeded>true</OperationSucceeded>
</OperationResult>
</GetConsumerHoldsResponse>


This is how I have defined the DS:
dcl-ds GetConsumerHoldsResponse likeDS(GetConsmrHldsResponse_T);

dcl-ds GetConsmrHldsResponse_T qualified ;
Holds likeDS(Holds_T);
MessageID varchar(50) ;
OperationResult likeDS(OperationResult_T);
End-Ds;

dcl-ds Holds_T qualified ;
Hold likeDS(HoldArray_T) dim(10) ;
ArrCnt_Hold int(5:0) inz(0);
End-Ds;

dcl-ds HoldArray_T qualified;
Type varchar(50) ;
Process varchar(50) ;
SuspendedFunctions likeDS(SuspFncts_T) ;
CreatedBy varchar(50) ;
CreateDate varchar(50) ;
ReleaseDate varchar(50) ;
End-Ds;

dcl-ds SuspFncts_T qualified ;
string likeDS(stringArray_T) dim(10) ;
ArrCnt_SuspFncts int(5:0) inz(0);
End-Ds;

dcl-ds stringArray_T qualified;
string varchar(50) ;
End-Ds;

I am getting hung up on the SuspendedFunctions and String I think.

Any help would be appreciated.
Kerwin


-----Original Message-----
From: Justin Taylor [mailto:JUSTIN@xxxxxxxxxxxxx]
Sent: Saturday, July 13, 2019 7:05 AM
To: rpg400-l@xxxxxxxxxxxxxxxxxx
Subject: Re: XML-INTO attribute & sub-level

Thank you so very much!!!!



I spend an hour or two reading docs and examples, as well as trying countless permutations. Who knows how it would turned out had I seen the missing field.



Thanks


________________________________
From: Barbara Morris <bmorris@xxxxxxxxxx>
Sent: Friday, July 12, 2019 5:41 PM
To: rpg400-l@xxxxxxxxxxxxxxxxxx
Subject: Re: XML-INTO attribute & sub-level

On 2019-07-12 5:40 PM, Justin Taylor wrote:
I can't seem to get the DS defined properly to parse this XML. I've never dealt with XML that had an attribute on parent item (the ID on Address), and I suspect that's my problem.

Here's the XML:
<AddressValidateResponse><Address ID="0"><Address2>6406 IVY
LN</Address2><City>GREENBELT</City><State>MD</State><Zip5>20770</Zip5>
<Zip4>1441</Zip4></Address></AddressValidateResponse>

Here's the applicable RPG code:
Dcl-ds lAddrValidResponseDs qualified inz dim(1) ;
id int(10) ;
Dcl-ds address ;
...

Justin, "ID" is a child of Address, so you should define id as a subfield of Address, not lAddrValidResponseDs.

Dcl-ds lAddrValidResponseDs qualified inz dim(1) ;
Dcl-ds address ;
id int(10) ;
...

But you have some other problems.

Your lAddressValidateResponseDs is an array, so XML-INTO is expecting an outer element (with any name) to contain the data for the array.

If you array was called "arr", and you did xml-into arr, then XML-INTO would expect the XML to look like this:
<something><arr>...</arr><arr>...</arr><arr>...</arr></something>
It's interpreting <AddrValidResponse> as the outer XML tag that would contain the actual data for the data structure array.

The reason it's not giving an error is that it's not finding data for any array element, so it is putting zero in the PSDS subfield that says how many elements were set.

You could remove the DIM from the data structure, or specify an index for the array on the XML-INTO operation if your XML doesn't represent an array.

But wait, that's not all. You also need to code option 'case=any', because your XML is in mixed case.

And finally, you're missing a subfield for the "state" in the XML.

Ops, not quite finally. You either need to give your data structure the same name as the outer element in the XML, or you need to use the path option so XML-INTO is happy that the XML matches your data structure.

This works:

Dcl-ds lAddrValidResponseDs qualified inz;
Dcl-ds address ;
id int(10) ; // move this
address2 varChar(255) ;
city varChar(255) ;
state varChar(255) ; // add this
zip5 packed(5) ;
zip4 packed(4) ;
End-ds ;

Xml-Into lAddrValidResponseDs %xml(lFileName
: 'doc=file case=any path=AddressValidateResponse');

--
Barbara




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.