I only need Powershell for this task and only have experience with coding in Stata - help would be much appreciated!
I have a large number of xml files where each one is a single record from a household survey, so it has variable names and responses from one person.
I need to convert those files to a csv file. From reading other posts I understand that I need to loop over the files, but I don’t know how to tell Powershell that I want all responses to be exported.
I’ve tried something like this:
`$items = Get-ChildItem C:\Users\fs59\Desktop\temp* -Include *.xml
foreach ($item in $items) {
$xml = [XML](Get-Content $item)
$xml | Export-Csv -Path C:\Users\fs59\Desktop\temp\myoutput.csv -NoTypeInformation -Append
} `
This runs without an error but the output does not contain the survey responses.
The survey has a lot of ‘routing’ so if people give a certain answer, they are routed to a relevant follow-up question.
UPDATE:
UPDATE: Hi, I have managed to send the results to csv but the output is one long column. Is there a way of having the output in several rows, one per each xml file?
# Get all XML files
$items = Get-ChildItem C:\Users\user\Desktop\test\* -Include *.xml
# Loop over them and append them to the document
foreach ($item in $items) {
$inputFile = [XML](Get-Content $item) #load xml document
#export xml as csv
$inputFile.TT_client_survey_2018_v1.ChildNodes | Export-Csv -Path C:\Users\user\Desktop\test\myoutput12.csv -NoTypeInformation -Append
}