Page 1 of 1

Dataset to XML String

Posted: Tue May 28, 2019 1:45 pm
by patgilmour
Hi,

I have an XML dataset that I need to convert to a string (to write to a variable).

I can easily access the dataset with

Code: Select all

var jData = job.getDataset("Data");
but I can find no method for converting it to a string.

I assume I have to write the dataset to a temporary text file then read that file, but I can't find a way to write the dataset to a text file.

Any suggestions?

Many thanks,

Pat

Re: Dataset to XML String

Posted: Tue May 28, 2019 4:57 pm
by freddyp
A dataset IS a file, so all you need to do is read it:

Code: Select all

var datasetAsString = File.read( jData.getPath());

Re: Dataset to XML String

Posted: Tue May 28, 2019 5:01 pm
by patgilmour
freddyp wrote: Tue May 28, 2019 4:57 pm A dataset IS a file, so all you need to do is read it:

Code: Select all

var datasetAsString = File.read( jData.getPath());
Thanks Freddy - that does the trick!

Here's a working version for anyone who needs the same:

Code: Select all

// Load the Dataset
var jobDataset = job.getDataset( "JobXML" );
	
// Read the dataset as string from the file
var datasetAsString = File.read( jobDataset.getPath());
	
// Write result to message log	
s.log(-1, "var: datasetAsString = " + datasetAsString);