0

I have an attribute "Count" in my xml , and when I am trying to access the values of the attribute it giving the count of the array

$Count = $xml.Para.Lic.Counter.Count

Any suggestions would be really helpful

2
  • Possibly a duplicate of stackoverflow.com/questions/12212452/… Commented Jun 16, 2017 at 18:56
  • @Jay Buckman:Actually I am trying the same way $Count = $xml.Para.Lic.Counter I select Count , but still its giving the count of array not values Commented Jun 16, 2017 at 19:02

2 Answers 2

1

You can use single quotes around names:

$Count = $xml.Para.Lic.Counter.'Count'

However, if 'Counter' is an array, you need to access an instance to get the attribute value:

    $Count = $xml.Para.Lic.Counter[0].Count
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply , I am still not able to fetch the values , its still taking count
taking count of what?
0

Both of these work. Maybe there is something else wrong with your XML?

$xml = Get-Content test.xml      
$xml.catalog.counter.Count
$xml.catalog.counter.'Count'

Loading the following test.xml

<?xml version="1.0"?>
<catalog>
    <counter count="150">
    </counter>
</catalog>

Comments

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.