简体   繁体   English

powershell 按级别格式将 xml 转换为 csv(或 excel)

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

i have a xml file like this:我有一个像这样的 xml 文件:

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

I want to convert this xml to csv with this format:我想用这种格式将此 xml 转换为 csv:

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

Does anyone have any idea with this using powershell?有人知道使用 powershell 吗?

We have created a sample xml file in our local environment with the below content.我们在本地环境中创建了一个示例 xml 文件,内容如下。

<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.使用下面的 PowerShell cmdlet,我们尝试转换为 csv 它工作正常。

Here are the PowerShell Cmdlets:以下是 PowerShell Cmdlet:

[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:以下是样品 output 供参考:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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