SAMPLE.XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Document Date="2013-09-06T11:55:29.151-04:00">
<Asset applicationName="Sample" id="301">
<componentsSecurity="true" EnterpriseUtil="true" StateManagement="true" smtp="true"/>
</Asset>
</Document>
MY PROBLEM
I'm having trouble trying to dynamically parse the "components" element - because any given Asset may have different components (attributes) listed, I would like to loop through the element and call a function with the attribute name and the value as the 2 parameters. The script below is as close as I can get...now I'm stuck.....please help!
MY SCRIPT
$xml = [xml](Get-Content "C:\sample.xml")
$NodeList = $xml.selectnodes("/Document/Asset/components/@*")
foreach ($AttributeValue in $NodeList) {
#This displays the "value" of the attribute (ie: true)
$AttributeValue
#This displays the "name" of the attribute (ie: Security, EnterpriseUtil, etc...)
$AttributeValue.ToString()
#As soon as I try to do something simple like a write-host the "$AttributeValue" comes out blank
Write-Host "-" $AttributeValue.ToString() "-" $AttributeValue "-"
#Eventually I will call a function with the 2 parmeters "name" & "value"
}