简体   繁体   中英

powershell convert xml to csv(or excel) by level format

i have a xml file like this:

<a>
   <a.1>
      <data a.1></data a.1>
   </a.1>
</a>

I want to convert this xml to csv with this format:

Column1  | Column2 |  column3
<a>      |         |
         |  <a.1>  |
         |         |  <data a.1></data a.1>
         |  </a.1> |
</a>     |         |

Does anyone have any idea with this using powershell?

We have created a sample xml file in our local environment with the below content.

<departments>  
<item>  
<deptid>100</deptid>  
<deptname>marketing</deptname>  
<employeecount>1000</employeecount>  
</item>  
</departments>  

Using the below PowerShell cmdlets, we tried converting to csv it is working fine.

Here are the PowerShell Cmdlets:

[xml]$de=Get-Content -Path C:\Users\Downloads\depart.xml  
$de.departments.ChildNodes|Export-Csv C:\Users\Downloads\depart.csv -NoTypeInformation -Delimiter:","

Here is the sample output for reference:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM