gpt4 book ai didi

asp.net - 使用 web.config 转换在根元素上设置多个属性

转载 作者:行者123 更新时间:2023-12-02 10:06:54 26 4
gpt4 key购买 nike

在 Visual Studio(web.config 转换)中,我想要执行一个转换,该转换在根元素上添加两个属性。一种属性有效(但多种属性无效)。我可以在一个子元素上设置多个属性。我尝试过使用或不指定属性名称的 SetAttributes,但没有成功。

想法??

示例

    <element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="SetAttributes" attrOne="One" attrTwo="Two">
<children>
<child name="One" xdt:Transform="SetAttributes" attrOne="One" attrTwo="Two" />
</children>
</element>

期望的效果

    <element attrOne="One" attrTwo="Two">
<children>
<child name="One" attrOne="One" attrTwo="Two" />
</children>
</element>

“element”部分实际上是 web.config 文件的自定义部分......就像这样:

<configuration>

... <element configSource="App_Data\element.config" />

此转换旨在用于 element.config 文件(使用慢速猎豹)

更新这显然也不起作用:

<element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="Replace" attrOne="One" attrTwo="Two">
<children>
<child name="One" attrOne="One" attrTwo="Two" />
</children>
</element>

但这确实:

<element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="Replace" attrOne="One">
<children>
<child name="One" attrOne="One" attrTwo="Two" />
</children>
</element>

一旦根元素上有超过 1 个属性,它就会失败

最佳答案

您是否尝试过像这样的文档转换,通过将要设置的属性列表传递给 SetAttribute() 来同时设置多个属性?

参见here形成更多信息。

具体来说:Transform="SetAttributes(一个或多个属性名称的逗号分隔列表)"

<element xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xdt:Transform="SetAttributes(attrOne,attrTwo)" attrOne="One" attrTwo="Two">
<children>
<child name="One" xdt:Transform="SetAttributes(attrOne,attrTwo)" attrOne="One" attrTwo="Two" />
</children>
</element>

关于asp.net - 使用 web.config 转换在根元素上设置多个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11735815/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com