IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Topic Options
#57604 - 07/31/20 08:22 AM Read an external xml file from PP design template
De12345 Offline
OL Newbie

Registered: 09/14/18
Posts: 17
Hi,

I have an xml file at location "C:\PlanetPress\programs\env.xml" and contains the below contents in it.

<?xml version="1.0" encoding="utf-8"?>
<root>
<documents>
<document>
<isSpecimen value="False" />
<environment value="QA" />
<url value="https://www.QAServices.com/report-search" />
<market value="NA" />
</document>
</documents>
</root>

Want to read the environment and the url value of the xml from PP editor.

Please help me in this regard.

Thanks

Top
#57605 - 08/03/20 07:35 AM Re: Read an external xml file from PP design template [Re: De12345]
jim3108 Offline
OL Expert

Registered: 04/19/10
Posts: 316
Loc: London, UK
If you're using a workflow process to drive your template, you are best doing this by creating a Local Variable for that process, populating it with the relevant XML and then reading that from the template. You can use Set Job Infos and Variables, select your variables and assign them using:

Code:
xmlget('/root[1]/documents[1]/document[1]/environment[1]/@value',Value,KeepCase,NoTrim)

Code:
xmlget('/root[1]/documents[1]/document[1]/url[1]/@value',Value,KeepCase,NoTrim)

You can read the variables from within the template by calling ExpandString('%{MyLocalVar}') in PressTalk or as a custom data selection.

However, if you aren't using workflow and wish to read an external file from the template, you'll need the execscriptfile function in PressTalk. This is designed to drive an external script much like the one you run under the Run Script action in workflow.

More information about that function: ExecScriptFile.

You'd need a VBScript or similar which - when prompted - reads your XML file and returns the values you require.
Note: The script will return a single value and so you'd need to delimit the return values such that you can separate them again.

The first approach is by far the recommended course of action (where possible).

Hope this helps.

Regards,

James.

Top
#57606 - 08/03/20 09:39 AM Re: Read an external xml file from PP design template [Re: jim3108]
De12345 Offline
OL Newbie

Registered: 09/14/18
Posts: 17
Thank You jim3108
This particular xml file is not the actual data file, we have a scenario where we cannot add additional data to the data file(as this would be a huge change in other application) so we are planning to obtain few data outside that data file.
we need to test a URL which will used in the PP design template. but hardcoding the URL in the design will not be best practice as URL changes according to the environment like QA , UAT etc. So everytime before deployment we have to change the URL and deploy. Hence we were planning to place a separate xml and access the value from it.

Thanks you for the link regarding execscriptfile.
There are around 90 process(each process use a different design template) in the workflow so I will have to add "Set JobInfos and Variables" for each and every process is that correct ?
if I go with execscriptfile in pp design will I be able to return some string values back to the design ?

Top
#57607 - 08/03/20 09:45 AM Re: Read an external xml file from PP design template [Re: De12345]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
To add my grain of salt...
Will each of your 90 processes access that same env.xml file?
If so, you might end-up with system file access issue.
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#57608 - 08/03/20 11:07 AM Re: Read an external xml file from PP design template [Re: Jean-Cédric]
De12345 Offline
OL Newbie

Registered: 09/14/18
Posts: 17
yes that was the plan ... but if execscriptfile in design works then i will proceed with that.
if I go with execscriptfile in pp design will I be able to return some string values back to the design ?
Could you please guide me with this. Thanks

Top
#57609 - 08/03/20 11:24 AM Re: Read an external xml file from PP design template [Re: De12345]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
If in each environment the values are the same for each Template, I would suggest using Global variables instead of Local ones.
This way, each of your Template can share the info.
You should as well have a Startup process which only function is to load up the values from that env.xml file.

You could as well setup another process which update the Global variables should the env.xml file is updated whilst PPWatch is still running.

If you go this way, then you do not need the Execscriptfile PressTalk command.
You only need to use the ExpandString one.
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#57611 - 08/03/20 12:59 PM Re: Read an external xml file from PP design template [Re: Jean-Cédric]
De12345 Offline
OL Newbie

Registered: 09/14/18
Posts: 17
Excellent suggestion.. Thanks a lot

Top
#57612 - 08/03/20 03:28 PM Re: Read an external xml file from PP design template [Re: Jean-Cédric]
De12345 Offline
OL Newbie

Registered: 09/14/18
Posts: 17
Hi,
As you suggested I have created a Startup process and a global variable as below :
1)Folder listing
2)Load an external file (env.xml)
3)Set Job Infos and Variables
%{global.GlobalVar} = xmlget('/root[1]/documents[1]/document[1]/url[1]/@value,Value,LowerCase,Trim)
4) Delete

The globalvar is set to blank, not sure where I went wrong.


-----------Xml is as below-----------------
<?xml version="1.0" encoding="utf-8"?>
<root>
<documents>
<document>
<isSpecimen value="False" />
<environment value="UAT" />
<url value="https://uat.services.com/report/" />
<market value="NA" />
</document>
</documents>
</root>

--------Output-------------------
WPROC: Startup process (thread id: 24664) - 00:40:22

Starting plugin Load External File - 00:40:23
Filename "C:\PlanetPress\Environment\env.xml" expanded to "C:\PlanetPress\Environment\env.xml"
Plugin Load External File completed successfully - 00:40:23 (elapsed time: 00:00:00:002)

Starting plugin Set Job Infos and Variables - 00:40:23
Value: xmlget('/root[1]/documents[1]/document[1]/url[1]/@value,Value,LowerCase,Trim)
JobInfo/Variable %{global.GlobalVar} is set to ""
Plugin Set Job Infos and Variables completed successfully - 00:40:23 (elapsed time: 00:00:00:002)

Starting plugin Delete - 00:40:23
Deleting file : debug7E607658.dat, size: 285 bytes
Plugin Delete completed successfully - 00:40:23 (elapsed time: 00:00:00:000)

Top
#57613 - 08/03/20 05:37 PM Re: Read an external xml file from PP design template [Re: De12345]
jim3108 Offline
OL Expert

Registered: 04/19/10
Posts: 316
Loc: London, UK
From what I can see, your code is lacking the trailing apostrophe (') after the word "value".

This should read as follows:
Code:
xmlget('/root[1]/documents[1]/document[1]/url[1]/@value',Value,LowerCase,Trim)

Rather than manually edit this, simply right-click and select Get Data Location with the target file loaded as the debug file in that process.

Regards,

James.

Top
#57616 - 08/04/20 05:40 AM Re: Read an external xml file from PP design template [Re: jim3108]
De12345 Offline
OL Newbie

Registered: 09/14/18
Posts: 17
Thanks James. That worked.

Top