I want to convert the below XML to CSV. Though it has header line information in the XML file.
<?xml version="1.0" encoding="UTF-8"?>
<myfile>
<updatetime>2019-07-30 08:30:30</updatetime>
<process code="PRS1234" name="PROCESS1234" />
<equipment code="EQP1234" name="EQUIPMENT1234" />
<product type="equipment" planned="300" time="36000" cycletime="20" />
<shift code="1" timestart="2019-07-30 02:00:00">
<order index="1" goodproduct="500" defectproduct="5" time="2019-07-30 02:00:00" />
<order index="2" goodproduct="980" defectproduct="7" time="2019-07-30 03:00:00" />
<order index="3" goodproduct="1200" defectproduct="12" time="2019-07-30 04:00:00" />
<order index="4" goodproduct="1800" defectproduct="15" time="2019-07-30 05:00:00" />
<order index="5" goodproduct="2500" defectproduct="15" time="2019-07-30 06:00:00" />
<shift>
<shift code="2" timestart="2019-07-30 07:00:00">
<order index="1" goodproduct="600" defectproduct="5" time="2019-07-30 07:00:00" />
<order index="2" goodproduct="980" defectproduct="7" time="2019-07-30 08:00:00" />
<order index="3" goodproduct="1500" defectproduct="8" time="2019-07-30 09:00:00" />
<order index="4" goodproduct="1700" defectproduct="11" time="2019-07-30 10:00:00" />
<order index="5" goodproduct="3000" defectproduct="15" time="2019-07-30 11:00:00" />
</shift>
</myfile>
I can get values for the desired nodes. This is what I have done.
[xml]$inputFile = Get-Content "Q:\XML\FileComplex.xml"
$inputFile.myfile.product | Select-Object -Property type,planned,time,cycletime | ConvertTo-Csv -NoTypeInformation -Delimiter ";" | Set-Content -Path "Q:\XML\FileComplex.csv" -Encoding UTF8 "
What I'm trying to achieve is to combine all desired information together and to get it as one record of the CSV file, which is like this
updatetime | code(process) | name(process) | code(equipment) | name(equipment) | type(product) | planned(product) | time(product) | cycletime(product) | goodproduct(shift(code) is 1 and index is max) | defectproduct(shift(code) is 1 and index is max) | goodproduct(shift(code) is 2 and index is max) | defectproduct((shift(code) is 2 where index is max)
2019-07-30 08:30:30 | PRS1234 | PROCESS1234 | EQP1234 | EQUIPMENT1234 | equipment | 300 | 36000 | 20 | 2500 | 15 | 3000 | 15
I really appreciate your support!!
Thanks in advance Natasha