1

I'm trying to use Web Deploy 3.0 to make changes to my web.config before deployment. Let's say I have the following xml:

<node>
    <subnode>
        <connectInfo httpURL="http://LookImAUrl.com" />
    </subnode>
<node>

And I'd like to match just the "http" in "http://..." so that I can potentially replace it with https.

I looked into XPath string functions and understand them -- I just don't know how to put them in the middle of an expression, for example:

"//node/subnode/connectInfo/@httpURL/substring-before(../@httpURL,':')" 

That's basically what I want to do, but it doesn't look right.

4

2 回答 2

1
 "//node/subnode/connectInfo/@httpURL/substring-before(../@httpURL,':')" 

这基本上就是我想要做的,但它看起来不正确。

但它是正确的,并且会匹配http。

(顺便说一句,你可以在没有 ..

    //node/subnode/connectInfo/@httpURL/substring-before(.,':')

)

但是,它将返回字符串“http”,而不是某种指向 @httpUrl 值的指针,这是不可能的,因为值中没有部分节点。

(在 XPath 2 中)您可以返回属性和一个新值,然后可能在调用语言中更改它

    //node/subnode/connectInfo/@httpURL/(., concat("https:", substring-after(.,':')))
于 2012-09-06T21:20:45.530 回答
1

使用 XPath 1.0,如果要返回 URL 的初始部分,请使用:

substring-before(//node/subnode/connectInfo/@httpURL,':')

请注意,这将仅返回第一个connectInfo元素的值。

如果要获取connectInfo使用 HTTP 的节点:

//node/subnode/connectInfo[starts-with(@httpURL,'http:')]

如果你想得到所有httpURL使用 HTTP 的东西:

//node/subnode/connectInfo/@httpURL[starts-with(.,'http:')]
于 2012-09-07T12:25:12.863 回答