You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell+XML制作Toast Notification跳转含=字符链接报错如何解决

问题解决方法

你遇到的报错不是=字符导致的,是XML语法规则的强制要求:XML 中&是预定义实体的开头标识,直接放在属性值中时,解析器会认为&后需要跟随实体名和结束符;,识别到不符合规则的=就会抛出对应错误。

有两种可选用的解决方法:

方案1:手动转义URL中的&符号

直接将链接里所有的&替换为XML实体&即可,修改后的对应XML代码如下:

<action arguments="https://part_of_the_link.aspx?C_ECRAN=HELP5_REQ_SYS&amp;Type=LINK&amp;Action=A&amp;FieldName=C_OBJETSERVICE&amp;FieldValue=THING" content="Open Web Page" activationType="protocol" />

修改后解析器就可以正常识别XML结构,点击按钮时系统会自动将&amp;还原为&,不影响链接跳转。

方案2:使用PowerShell自动转义(更稳妥,适合动态拼接链接的场景)

如果你的链接是动态生成的,手动转义容易遗漏,可以用PowerShell自带的转义方法处理链接后再填入XML,完整示例如下:

# 先定义原始链接
$targetUrl = "https://part_of_the_link.aspx?C_ECRAN=HELP5_REQ_SYS&Type=LINK&Action=A&FieldName=C_OBJETSERVICE&FieldValue=THING"
# 自动转义XML特殊字符
$escapedUrl = [System.Security.SecurityElement]::Escape($targetUrl)

[xml]$Toast = @"
<toast scenario="$Scenario">
    <visual>
    <binding template="ToastGeneric">
        <group>
            <subgroup>
                <text hint-style="title" hint-wrap="true" >$TitleText</text>
            </subgroup>
        </group>
        <group>
            <subgroup>
                <text hint-style="Body" hint-wrap="true" >$BodyText1</text>
            </subgroup>
        </group>
        <group>
            <subgroup>     
                <text hint-style="base" hint-wrap="true" >$BodyText2</text>
            </subgroup>
        </group>
        <group>
            <subgroup>     
                <text hint-style="body" hint-wrap="true" >$BodyText3</text>
            </subgroup>
        </group>
    </binding>
    </visual>
    <actions>        
        <action arguments="$escapedUrl" content="Open Web Page" activationType="protocol" />
        <action activationType="system" arguments="dismiss" content="$DismissButtonContent"/>
    </actions>
</toast>
"@

该方法会自动处理所有XML需要转义的特殊字符(&、<、>、"、'),避免后续修改链接时再次出现同类问题。

内容的提问来源于stack exchange,提问作者Noemie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 12:27:02