<contents>
<content>
<name>John</name>
<active>0</active>
</content>
<content>
<name>Peter</name>
<active>0</active>
</content>
</contents>
[xml]$nameactives = Get-Content C:\test\names.xml
ForEach ($activename in $nameactives.contents.content.name)
{
$checkedlistbox1.Items.Add($activename)
}
foreach ($items in $checkedlistbox1.CheckedItems)
{
[xml]$nameactives = Get-Content C:\test\names.xml
ForEach ($activenames in $nameactives.contents.content)
{
?????????
}
$nameactives.Save("C:\test\names.xml")
}
I need to change the value of <active></active> to 1 or 0 based on name selected from $checkedlistbox1.CheckedItems
XML parsing changing values from CheckedListbox
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: XML parsing changing values from CheckedListbox
WHat is it that you are having an issue with? To alter an XML item just assign its #text property.
To find a specific item in an XML file use an XPath expression.
To find a specific item in an XML file use an XPath expression.
Re: XML parsing changing values from CheckedListbox
my issue is $activenames.active = 1 below which changes all <active></active> instead of only the items in the $checkedlistbox1.CheckedItems
foreach ($items in $checkedlistbox1.CheckedItems)
{
[xml]$nameactives = Get-Content C:\test\names.xml
ForEach ($activenames in $nameactives.contents.content)
{
$activenames.active = 1
}
foreach ($items in $checkedlistbox1.CheckedItems)
{
[xml]$nameactives = Get-Content C:\test\names.xml
ForEach ($activenames in $nameactives.contents.content)
{
$activenames.active = 1
}