Samselvaprabu
Samselvaprabu

Reputation: 18187

How to separate the attribute from xpath?

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

Answers (2)

FoxDeploy
FoxDeploy

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

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200373

Use the -split operator:

$xPath = "/configuration/system.serviceModel/services/service/endpoint/@binding"

$node, $attribute = $xPath -split '/@', 2

Upvotes: 1

Related Questions