2015-04-29 34 views
0

我想從xPath中分割屬性。如何從xpath中分離屬性?

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

$node = $xPath.split("@")[0] 
$attribute = $xPath.split("@")[1] 

$屬性具有正確的價值 「綁定」

但節點XPath是 「/configuration/system.serviceModel/services/service/endpoint/」。在結尾處還有一個額外的「/」。我想擺脫這一點。

如何將其刪除?

回答

1

使用-split操作:

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

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

我會用.Replace()方法只需更換/結合/ /綁定,就像這樣:

$xPath.Replace("/endpoint/","/endpoint") 
>/configuration/system.serviceModel/services/service/endpoint