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

Outlook Add-In如何读取XML黑名单内容并存入字符串数组?

解决方案

你原有代码的问题出在两处:

  • 查询的节点是父级attachmentRefs,而非实际存储黑名单词汇的attachmentRef子节点
  • 取值时调用了节点的Value属性,但目标词汇存储在attachmentRef节点的Name自定义属性中,无法通过Value获取

修正后的代码如下:

private string[] XMLReader() 
{
    string[] arr = XDocument.Load(@"C:\ProjektOutlook\outlookadresses\Add-In\Add-In\Resources\Blacklist.xml")
                    // 定位到每个词汇对应的attachmentRef子节点
                    .Descendants("attachmentRef")
                    // 提取每个节点的Name属性值
                    .Select(node => node.Attribute("Name").Value)
                    .ToArray();
    return arr;
}

如果需要兼容无Name属性的异常场景,可以增加空判断逻辑:

private string[] XMLReader() 
{
    string[] arr = XDocument.Load(@"C:\ProjektOutlook\outlookadresses\Add-In\Add-In\Resources\Blacklist.xml")
                    .Descendants("attachmentRef")
                    .Select(node => node.Attribute("Name")?.Value ?? string.Empty)
                    // 过滤空值
                    .Where(val => !string.IsNullOrWhiteSpace(val))
                    .ToArray();
    return arr;
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.24 05:24:07