Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8553887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:45:23+00:00 2026-06-11T14:45:23+00:00

I would like to create a Powershell script that automates parsing an XML, but

  • 0

I would like to create a Powershell script that automates parsing an XML, but collecting only certain information from it.

As it stands, right now, my script looks similar to this.

[xml]$xml = Get-Content .\myxml.xml
$foo_sub_length = $xml.report.foos.foo.length - 1
$foo_looper = 0
$foo_looper_brackets = "[$foo_looper]"
if ($foo_sub_length -eq "") {$foo_looper_brackets = ""}
do {
    $xml.report.foos.foo$foo_looper_brackets.bar
}
while ($foo_looper -le $foo_sub_length)

Basically, it needs to go through and print out all of the $xml.report.foos.foo.bar values. When I run this script, I receive the error,

Unexpected token 'node_looper_brackets' in expression or statement.
At C:\Users\notarealuser\Desktop\xmlscript.ps1:10 char:55          #not reflective of the above script
+ CategoryInfo          : ParserError: (foo_looper_brackets:String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
+     $xml.report.foos.foo$foo_looper_brackets <<<< .bar

Any ideas on why or how my looping is not working?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:45:24+00:00Added an answer on June 11, 2026 at 2:45 pm

    You might be better off extracting this info with XPath. If you’re not using XML namespaces this is pretty trivial (and namespaces only makes it slightly harder):

    PS> [xml]'<doc><title>Foo</title><title>Bar</title></doc>' | 
             Select-Xml '/doc/title' | Foreach {$_.Node.InnerText}
    
    Foo
    Bar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a Powershell script that will re-open IE each time
I have a Powershell script where I would like to create a generic List
I would like to create a powershell function that can take 2 different types
I would like to create a powershell script generating a report showing all compressed
I would like to create a c++ type that mimic the build-in type exactly.
I would like to create set of strings and below is the only limitation.
I would like to create a class that runs something (a runnable) at regular
I would like to create a virtual host in apache2, but I want it
I would like to use Powershell to create a couple of scheduled tasks, on
I would like create an inner shadow on my UIView on iPad like that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.