0

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 the < 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.

1
  • 1
    Can you show us what PowerShell script you've written so far? Commented Aug 17, 2011 at 15:16

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

Isn't $x.SelectNodes("//English") enough?
Probably, I just tend to be more explicit out of habit.
1

One way would be:

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

2 Comments

I think you probably meant this comment to be on my answer, but you are probably right that it would be sufficient.
@EBGreen - lol, sorry didn't even realize that I had commented on my own answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.