0

i want to convert a xml file to csv with powershell. how can i map the xml fields to csv? the inputs fields are variable .

i added 2 screenshots , the first is the xml input file , the second the expected csv output

$xml = @"
<?xml version="1.0" encoding="utf-8"?>
<DeviceConfig>
<Device Debiteurnummer="input" facuurnummer="input" factuurdatum="input" />
</DeviceConfig>
"@

 $xmlData = [xml]$xml

 $xmlData.DeviceConfig.ChildNodes | Export-Csv "c:\pstest\test.csv" -NoTypeInformation - 
 Delimiter:";" -Encoding:UTF8

enter image description here

enter image description here

Toine de L
  • 43
  • 3
  • Depending on your needs, it might also be an option to open the XML file in Excel, and then use the XML Source task pane to map the XML elements to your worksheet. You can save the results as a normal Excel file (or CSV, if you wish) and with the former, you can refresh the data whenever the XML source changes to immediately reflect the changes. – DocZerø Mar 17 '22 at 11:35
  • Please my question you might get better idea about to do. https://stackoverflow.com/questions/68912263/how-to-get-xml-field-value-using-csv-column-header-powershell – microset Mar 19 '22 at 08:01

0 Answers0