Reputation: 18187
I would like to split attribute from xPath .
$xPath = "/configuration/system.serviceModel/services/service/endpoint/@binding"
$node = $xPath.split("@")[0]
$attribute = $xPath.split("@")[1]
$attribute is having the correct value "binding"
but the node xpath is "/configuration/system.serviceModel/services/service/endpoint/". there is an extra "/" at then end . I want to get rid of that.
How to remove it?
Upvotes: 0
Views: 156
Reputation: 13547
I would use the .Replace() method to just replace /binding/ with /binding, like so:
$xPath.Replace("/endpoint/","/endpoint")
>/configuration/system.serviceModel/services/service/endpoint
Upvotes: 0
Reputation: 200373
Use the -split
operator:
$xPath = "/configuration/system.serviceModel/services/service/endpoint/@binding"
$node, $attribute = $xPath -split '/@', 2
Upvotes: 1