要去除返回报文中的 'xmlns' 命名空间属性,可以使用 XmlDocument 类来处理。以下是一种可能的方法:

using System.Xml;

public string RemoveXmlNamespace(string xmlString)
{
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(xmlString);
    
    // 获取根节点
    XmlElement root = xmlDoc.DocumentElement;
    
    // 移除根节点的 'xmlns' 属性
    root.RemoveAttribute('xmlns');
    
    // 将修改后的 XML 文档转换为字符串返回
    return xmlDoc.OuterXml;
}

你可以将上述代码添加到你的 C# Web 服务中的方法中,然后将返回报文传递给 RemoveXmlNamespace 方法,它将返回一个去除了 'xmlns' 命名空间属性的字符串。

C# Web Service: 如何去除返回报文中的 xmlns 命名空间

原文地址: https://www.cveoy.top/t/topic/p7n1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录