xml: get item's value, exclude comments from selection

by Feb 21, 2012

Hi All. I have xml file:


<?xml version="1.0" encoding="utf-8" ?>
    <variables>
        <!--My first variable-->
        <acsrv>%AppData%MyCompanyNameMySoftName</acsrv>
        <!--My second variable-->
        <wproj>%AppData%MyCompanyNameMySoftName</wproj>
    </variables>

I need for each 'variables' item create new environment variable (in user profile). I can't get value for xml item. My code:

# Current directory
$curDir = $MyInvocation.MyCommand.Definition | split-path -parent
# xml file full name
$xmlFile = "$curDirvariables.xml"
# Reed variables from xml file
$xmldata = [xml](Get-Content $xmlFile)
# Create or reset variables
$xmldata.variables foreach {[Environment]::SetEnvironmentVariable($_.Name, $_.Value, "User")}

1. What should I write instead of "$ _.Value"? 
2. How from sampling to eliminate objects of comments? 

I read it chapter, but haven't found the answer.

Sorry for my English
Regards