Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

csv to xml conversion, element naming problem

$
0
0

Script:

#Convert CSV FILES TO XML
#Test if directory has and csv files, if yes then proceed
if((test-path c:\temp\csv\*csv) -eq 1){
    $csvpath= get-childitem c:\temp\csv\*.csv| foreach-object { $_.FullName }
    $csv=Import-Csv $csvpath
    $xml=[xml]'<csvobjects/>'
    $p=$csv|gm -MemberType NoteProperty|%{$_.Name}
    $csv|%{
         $row=$xml.CreateElement('row')
        $r=$_;
        $p|%{
             $el=$xml.CreateElement($_)
             $el.InnerText=$r.($_)
             [void]$row.appendChild($el)
         }
         [void]$xml.DocumentElement.AppendChild($row)
    }
    $currdate=get-date -f MM_dd_yyyy_hh
    $f= "c:\temp\xml\$($currdate).xml"
    $xml.Save($f)

#if the directory does not have any .csv files then break
else {
break
}



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>