Working with XML

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Working with XML

Post by Tourless » Thu Apr 06, 2023 3:32 pm

Hi Folks,

I'm working with two XML files which I can read into a variable but once I have the data into one variable I'm not sure how to break it out into individual variable that I can work with (adding certain vars, doing other math, etc).

My code is basic so far simply because I'm not sure where to go from here...

Code: Select all

LabelToVar>XML,strm1XML
LabelToVar>XML,strm2XML
ReadFile>\\MENTOR1\Program Files (x86)\Milnor\Mentor\ProdData.xml,strm1XML
ReadFile>\\MENTOR2\Program Files (x86)\Milnor\Mentor\ProdData.xml,strm2XML
This leaves me with one var containing all the tags for each xml file.

My xml files are identical and both look like this...
- <ProductionData>
<Transfers>100</Transfers>
<RunTime>21505</RunTime>
<HoldTime>7690</HoldTime>
<SteamTime>42471</SteamTime>
<FillFlushTime>4210</FillFlushTime>
<FillFlushCounts>62</FillFlushCounts>
<RunTBT>21505</RunTBT>
<LastTBT>1527</LastTBT>
<TotalWeight>0</TotalWeight>
<TotalNominalWeight>251850</TotalNominalWeight>
<PFTankDrainCounts>0</PFTankDrainCounts>
<PressTankDivertCounts>0</PressTankDivertCounts>
<PressTankDivertTime>0</PressTankDivertTime>
<CumulativeTransfers>11815</CumulativeTransfers>
<CumulativeRunTime>2247347</CumulativeRunTime>
<CumulativeHoldTime>817798</CumulativeHoldTime>
</ProductionData>

They are automatically updated every few minutes but I'm looking to use them on an hourly basis to report some data individually and for both combined. How can I breakdown my existing variables into the individual components of their tags?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Working with XML

Post by Dorian (MJT support) » Thu Apr 06, 2023 4:41 pm

I had to remove the "- " before <ProductionData>.

This should get you started. Ofcourse instead of labeltovar you'd just use ReadFile.

Code: Select all

labeltovar>XML,TheXML
stringreplace>TheXML,- <ProductionData>,<ProductionData>,TheXML

Let>expr=ProductionData/Transfers/text()
XMLParse>TheXML,expr,val,len
mdl>val


/*
XML:
- <ProductionData>
<Transfers>100</Transfers>
<RunTime>21505</RunTime>
<HoldTime>7690</HoldTime>
<SteamTime>42471</SteamTime>
<FillFlushTime>4210</FillFlushTime>
<FillFlushCounts>62</FillFlushCounts>
<RunTBT>21505</RunTBT>
<LastTBT>1527</LastTBT>
<TotalWeight>0</TotalWeight>
<TotalNominalWeight>251850</TotalNominalWeight>
<PFTankDrainCounts>0</PFTankDrainCounts>
<PressTankDivertCounts>0</PressTankDivertCounts>
<PressTankDivertTime>0</PressTankDivertTime>
<CumulativeTransfers>11815</CumulativeTransfers>
<CumulativeRunTime>2247347</CumulativeRunTime>
<CumulativeHoldTime>817798</CumulativeHoldTime>
</ProductionData>
*/
Yes, we have a Custom Scripting Service. Message me or go here

Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Re: Working with XML

Post by Tourless » Thu Apr 06, 2023 4:57 pm

Oh that's a very good start, thank you very much Dorian! First time I'm working with xml files in any capaticy. This is a great jump start, thank you again!!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Working with XML

Post by Dorian (MJT support) » Thu Apr 06, 2023 5:06 pm

Always happy to help.
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts