Luis Diaz
asked on
Windows batch & VB Script & Powershell: convert xml into csv
Hello experts,
I have the following xml file (dummy file) in input folder.
I am looking for a vbscript & windows batch & powershell to generate the attached csv file in output folder.
How should I proceed?
If you have questions, please don’t hesitate to contact me.
Thank you in advance for your help.
export.xml
dummy-file-export.csv
I have the following xml file (dummy file) in input folder.
I am looking for a vbscript & windows batch & powershell to generate the attached csv file in output folder.
How should I proceed?
If you have questions, please don’t hesitate to contact me.
Thank you in advance for your help.
export.xml
dummy-file-export.csv
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
aligned values and header with xml and reference csv files and it works!!
Thank you very much for your help.
I tested with the following:
Thank you very much for your help.
I tested with the following:
$currentPath = Split-Path $script:MyInvocation.MyCommand.Path
$xmlFile = $currentPath + '\reference-export.xml'
$csvFile = $currentPath + '\csv-file.csv'
$userDefined = @(
'ID'
'Name'
'Program_Code'
'Status'
'Leader SESA'
'PMO1 SESA'
'PMPOPENDate'
'PMPSELECTDate'
'PMPDODate'
'PMPPRODUCEDate'
'PMPIMPLEMENTDate'
'PMPSELLDate'
'PMPCLOSEDate'
'OCPProcess'
'OwningOrg__code'
'Scope'
'Project Type'
)
$xml = [xml](Get-Content -Path $xmlFile)
$xml.SelectNodes('Projects/Project') | ForEach-Object {
$out = @{}
$out['ID_KEY'] = $_.SelectSingleNode('Idkey').InnerText
$out['Cardinality'] = $_.SelectSingleNode('Cardinality').InnerText
$_.SelectNodes('UserDefinedField') | ForEach-Object {
$out[$_.SelectSingleNode('name').InnerText] = $_.SelectSingleNode('value').InnerText
}
[PSCustomObject]$out
} | Select-Object -Property (@('ID_KEY', 'Cardinality') + $userDefined) |
Export-Csv -NoTypeInformation -Path $csvFile -Delimiter ';'
Write-Output "Done"
ASKER