Wed Aug 15, 2018 1:47 am
Login Register Lost Password? Contact Us


Open and load xml file

Questions around writing code and queries

Sun Nov 12, 2017 11:42 pm Change Time Zone

Hello,

I am looking for a way of opening a xml file and using it inside a LOADXML statement. Has anyone ever tries this?
francisco_escher
 
Posts: 3
Joined: Sun Nov 12, 2017 11:26 pm

Mon Nov 13, 2017 10:16 am Change Time Zone

Francisco,

If you look at the LOADXML docs, you'll see that it is not designed to read XML from a file. LOADXML was originally designed to make text from a SOAP-style XML stream available for use in ECL MACROs to generate ECL code. It was used to accomplish tasks such as taking user-chosen parameters from a website and generating ECL to fetch just those records meeting that set of parameters from data that contains too many possible parameter combinations to efficiently pre-write code for all the possibilities.

One way to get around this would be to use the ECL IDE's "drilldown" capability to get the XML from the file and output that as a workunit result, then use the "drilldown" technique to pass that result as a constant string to another workunit that uses LOADXML to load it and Template Language to parse it to generate ECL code to run your job. That technique will be discussed by Bob Foreman in the upcoming Tech Talk this Thursday, November 16, 2017 (https://hpccsystems.com/community/events/download-tech-talks-hpcc-systems-community-episode-9).

Of course, if you just want to parse the XML to extract data, then you don't need LOADXML at all. You can either define the file as an XML DATASET and create the proper RECORD structure using XPATH on each field definition (if it contains "well-formed" XML), or you can define it as a CSV or FLAT DATASET with a single variable-length STRING field, then use the PARSE function to extract your data from the XML text.

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1368
Joined: Wed Oct 26, 2011 7:40 pm

Mon Nov 13, 2017 11:27 am Change Time Zone

Thank you, Richard!

I know that the template language is such a powerful tool, and I had gone through the possibilities that you mentioned, but is not really what I was looking for.

My desire was to have xml files as 'config' files so I can load them as strings to automate ECL according to the xml I was loading (using template language as well).

I know I can build the string in ECL but the solution is not so elegant.

I have also tried to open the file with embeded c++ but this won't work as well.

I was wondering if there was a way of opening and loading the file once during compilation time...

Thanks again,
Francisco Escher.
francisco_escher
 
Posts: 3
Joined: Sun Nov 12, 2017 11:26 pm

Mon Nov 13, 2017 1:41 pm Change Time Zone

Francisco,
I was wondering if there was a way of opening and loading the file once during compilation time...
AFAIK, only through the "drilldown" technique I mentioned previously.

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1368
Joined: Wed Oct 26, 2011 7:40 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron