Topic Options
#58041 - 06/11/21 08:55 AM xml need help to calculate unit weight
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
For each Line segment, I need to find the unit weight: LineWeight/Quantity and put the answer at Unitweight. Can you help ?

<Line>
<Quantity>1.00</Quantity>
<ItemNumber>TOP63661</ItemNumber>
<ProductDescription/>
<UnitWeight/>
<CustomChar1/>
<CustomChar2>74</CustomChar2>
<CustomChar3>T W L</CustomChar3>
<CustomNumeric1/>
<LineWeight>50.00000</LineWeight>
</Line>
<Line>
<Quantity>10.00</Quantity>
<ItemNumber>JET502128</ItemNumber>
<ProductDescription/>
<UnitWeight/>
<CustomChar1/>
<CustomChar2>74</CustomChar2>
<CustomChar3>T W L</CustomChar3>
<CustomNumeric1/>
<LineWeight>0.08800</LineWeight>
</Line>
<Line>
<Quantity>10.00</Quantity>
<ItemNumber>JET502174</ItemNumber>
<ProductDescription/>
<UnitWeight/>
<CustomChar1/>
<CustomChar2>74</CustomChar2>
<CustomChar3>T W L</CustomChar3>
<CustomNumeric1/>
<LineWeight>0.10000</LineWeight>
</Line>

Top
#58044 - 06/14/21 11:49 AM Re: xml need help to calculate unit weight [Re: sygui]
MartinS Offline
OL Guru

Registered: 08/06/12
Posts: 129
Loc: Munich
so you need to calculate UnitWeight = LineWeight * Quantity and put the result back to the data file?

Top
#58047 - 06/14/21 02:49 PM Re: xml need help to calculate unit weight [Re: sygui]
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
I need to divide LineWeight per Quantity and put the results in Unitweight

Top
#58053 - 06/15/21 12:17 PM Re: xml need help to calculate unit weight [Re: sygui]
MartinS Offline
OL Guru

Registered: 08/06/12
Posts: 129
Loc: Munich
you could try with splitting at <Line>, doing the calculation and afterwards replacing <UnitWeight/> with the result of your calculation: <UnitWeight>#result#</UnitWeight>

Top
#58056 - 06/15/21 03:05 PM Re: xml need help to calculate unit weight [Re: sygui]
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
Martin, the problem is that I don't have any idea of how to calculate this with a script

Top
#58057 - 06/15/21 03:39 PM Re: xml need help to calculate unit weight [Re: sygui]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 651
Loc: Québec, Canada
Just a thought but if you intend to use the modified data in a form, you could do the calculation in it...no?
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#58060 - 06/16/21 07:15 AM Re: xml need help to calculate unit weight [Re: sygui]
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
Jean-Cedric, ok but how do I calculate it ?

Top
#58061 - 06/16/21 08:08 AM Re: xml need help to calculate unit weight [Re: sygui]
MartinS Offline
OL Guru

Registered: 08/06/12
Posts: 129
Loc: Munich
It's possible to do that in Workflow, but it needs a lot of steps.

First you need to add lines to your raw data file to add a root node (if not already being present), e.g.:
<data>

</data>
This could be done with two Add/Remove Text plugins.

Next you should have a Change Emulation plugin to mark your data to be XML.

Then use a XML Splitter to split on nodes <Lines>.

Next step is a Mathematical Operations plugin which extracts the xml fields for the operation needed and put the result in a job info variable, e.g. %9.

Afterwards get a Search and Replace plugin to replace <UnitWeight/> by <UnitWeight>%9</UnitWeight>

Next following two Add/Remove Text steps to remove the unncessary header of the xml split file and also remove the last line which is the root node closing tag.

And finally have a Send to Folder plugin with option "Concatenate files" enabled and Separator string \r\012.

That's it.

Top
#58062 - 06/16/21 11:21 AM Re: xml need help to calculate unit weight [Re: sygui]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 651
Loc: Québec, Canada
Well in your form, you need to setup a custom data selection with the following code:
Code:
=floattostr((strtofloat(XmlGet('/Lines[1]/Line['+inttostr(&current.line)+']/LineWeight[1]'))/strtofloat(XmlGet('/Lines[1]/Line['+inttostr(&current.line)+']/Quantity[1]'))))


My guess is that you will use Repeat in which case, that explains the use of inttostr(&current.line). If you do not need repeat, then the code line should be like this:
Code:
=floattostr((strtofloat(XmlGet('/Lines[1]/Line[1]/LineWeight[1]'))/strtofloat(XmlGet('/Lines[1]/Line[1]/Quantity[1]'))))


You should look at these documentation link in order to understand the code:

=floattostr((strtofloat(XmlGet('/Lines[1]/Line[1]/LineWeight[1]'))/strtofloat(XmlGet('/Lines[1]/Line[1]/Quantity[1]'))))

and this as well line repeat

Of course, this code is good for this specific XML that I created, based on what you have provided:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Lines>
<Line>
<Quantity>1.00</Quantity>
<ItemNumber>TOP63661</ItemNumber>
<ProductDescription/>
<UnitWeight/>
<CustomChar1/>
<CustomChar2>74</CustomChar2>
<CustomChar3>T W L</CustomChar3>
<CustomNumeric1/>
<LineWeight>50.00000</LineWeight>
</Line>
<Line>
<Quantity>10.00</Quantity>
<ItemNumber>JET502128</ItemNumber>
<ProductDescription/>
<UnitWeight/>
<CustomChar1/>
<CustomChar2>74</CustomChar2>
<CustomChar3>T W L</CustomChar3>
<CustomNumeric1/>
<LineWeight>0.08800</LineWeight>
</Line>
<Line>
<Quantity>10.00</Quantity>
<ItemNumber>JET502174</ItemNumber>
<ProductDescription/>
<UnitWeight/>
<CustomChar1/>
<CustomChar2>74</CustomChar2>
<CustomChar3>T W L</CustomChar3>
<CustomNumeric1/>
<LineWeight>0.10000</LineWeight>
</Line>
</Lines>
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#58063 - 06/17/21 11:14 AM Re: xml need help to calculate unit weight [Re: sygui]
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
I will try this, thks

Top