开发者

Parsing XML Files with PowerShell

开发者 https://www.devze.com 2023-03-28 22:54 出处:网络
To give an idea of how the XML code looks like that I am working with here. <content> <text id=\"new-users\">

To give an idea of how the XML code looks like that I am working with here.

<content>
<text id="new-users">
<Chinese>Nuevos usuarios</Chinese>
<English>New Users</English>
</text>
<text id="create-an-account">
<Chinese>Crear una Cuenta</Chinese>
<English>Create an Account</English>
</text>

I want to pull All of the English text between t开发者_如何学运维he < English > the test< /English > and have it listed then add a comma to the end. to export it to excel.

I can't understand what powershell is doing I am kind of lost. I can get "text" to print out a lot of times and I looked in to printing out the get-contents then piping the contents with a sort to only print the English and it didn't work.


So there are a couple of ways to get to the data. Here is the XPath way:

[xml]$x = Get-Content C:\Path\To\File.xml
$x.SelectNodes('//text/English') | Export-CSV C:\Path\To\Result.csv -NoTypeInfo


One way would be:

[xml] $xml = gc file.xml
$xml.content.text | select English | Export-CSV test.csv -notype
0

精彩评论

暂无评论...
验证码 换一张
取 消