Access #text Property Of XMLAttribute In Powershell


Answer :

Besides #text, you can also access XmlAttribute's value via Value property :

$attr = $xml.SelectSingleNode("//obj/indexlist/index[@name='DATE']/@value")  #print old value $attr.Value  #update attribute value  $attr.Value = "new value"  #print new value $attr.Value 

Note that Value in $attr.Value is property name of XmlAttribute. It doesn't affected by the fact that the attribute in your XML named value.


Don't select the attribute, select the node. The attributes of the node will be represented as properties and can be modified as such:

$node = $xml.SelectSingleNode("//obj/indexlist/index[@name='DATE']") $node.value = 'foo' 

Use a loop if you need to modify several nodes:

$nodes = $xml.SelectNodes("//obj/indexlist/index[@name='DATE']") foreach ($node in $nodes) {   $node.value = 'foo' } 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?