Dataset to XML String

Post Reply
patgilmour
Newbie
Posts: 13
Joined: Mon Jul 06, 2015 10:56 pm

Dataset to XML String

Post 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
freddyp
Advanced member
Posts: 1023
Joined: Thu Feb 09, 2012 3:53 pm

Re: Dataset to XML String

Post 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());
patgilmour
Newbie
Posts: 13
Joined: Mon Jul 06, 2015 10:56 pm

Re: Dataset to XML String

Post 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);
Post Reply