Sun Jul 21, 2019 8:41 am
Login Register Lost Password? Contact Us


Loading XML into a DATASET using PARSE.

Comments and questions related to the Enterprise Control Language

Mon May 20, 2019 10:25 am Change Time Zone

Hi,
Following up on a 2017 post on loading nested XML into a dataset:
https://hpccsystems.com/bb/viewtopic.php?f=8&t=5103&p=22723&hilit=nested+XML#p22723
I'm attempting to replace the FROMXML with PARSE.
The 'FROMXML' works fine (once one removes my typo in the source string :-()
But replacing FROMXML with:
Code: Select all
dd := DATASET([{x}],{STRING line});
PARSE(dd,line,PeopleRec,XML('Row'));

Fails syntex check with:
Code: Select all
Error:    Need to supply a value for field 'People' (37, 15), 2170,


So how does one load XML into a dataset using PARSE?
Yours
Allan

Hum, There is XMLPROJECT and this can be done with a transform, but I should not need to go down the 'transform' route.

XMLPROJECT works fine, but I don't really need the TRANSFORM
as I'm just setting fields in the record for the content of the tags in the xml file.
in the link.
Allan
 
Posts: 373
Joined: Sat Oct 01, 2011 7:26 pm

Mon May 20, 2019 1:39 pm Change Time Zone

The original post from 2017:
Code: Select all
NameRec := RECORD
  STRING Firstname{xpath('fname')};
  STRING Lastname{xpath('surname')};
END;

namesRec := RECORD
  UNSIGNED4 EmployeeID{xpath('NI')};
  DATASET(NameRec) names{xpath('name')}; //note the xpath
END;

PeopleRec := RECORD
    DATASET(NamesRec) People{xpath('/People')};
END;

x := '<Row>'
+'<People>'
+'<NI>1234567</NI>'
+'<name><fname>Allan</fname><surname>Wrobel</surname></name>'
+'<name><fname>Anna</fname><surname>Smith</surname></name>'
+'<name><fname>Nina</fname><surname>Harrison</surname></name>'
+'</People>'
+'<People>'
+'<NI>98765</NI>'
+'<name><fname>Colin</fname><surname>Harison</surname></name>'
+'<name><fname>James</fname><surname>Wilson</surname></name>'
+'<name><fname>Nick</fname><surname>Pine</surname></name>'
+'</People>'
+'</Row>';
rec := FROMXML(PeopleRec,x);
rec;

Works fine using FROMXML.

I'm trying the equivalent (nested dataset) using PARSE.
e.g.
Code: Select all
dd := DATASET([{x}],{STRING line});
PARSE(dd,line,PeopleRec,XML('Row'));


I can use XMLPROJECT, but don't really need the flexibility or power of a TRANSFORM.
Allan
 
Posts: 373
Joined: Sat Oct 01, 2011 7:26 pm

Mon May 20, 2019 2:09 pm Change Time Zone

I think FROMXML may be closer to what you want.
ghalliday
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 184
Joined: Wed May 18, 2011 9:48 am

Tue May 21, 2019 10:43 am Change Time Zone

Yea : Thanks, Richard.

Actually, it would be quite unusual to NOT to want to do some processing on ingested data, so XMLPROJECT and a TRANSFORM would almost always be needed anyway.

Yours

Allan
Allan
 
Posts: 373
Joined: Sat Oct 01, 2011 7:26 pm


Return to ECL

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron