【问题标题】:Change XML node attribute value via WCF servive通过 WCF 服务更改 XML 节点属性值
【发布时间】:2013-10-25 17:32:48
【问题描述】:
[ServiceContract]
public interface IParametersXMLService
{
    [OperationContract, XmlSerializerFormat]
    XmlNode GetCommonNode(string path);

    [OperationContract, XmlSerializerFormat]
    void SetCommonNode(string path, string value);
}

服务实现:

    public XmlNode GetCommonNode(string path)
    {
        XmlDocument xml = new XmlDocument();
        xml.Load(path);
        XmlNode node = (XmlNode)xml.DocumentElement;
        XmlNode commonNode = node.SelectSingleNode("/blabla/att);
        return commonNode;
    }

    public void SetCommonNode(string path, string value)
    {
        XmlDocument xml = new XmlDocument();
        xml.Load(path);
        XmlNode node = (XmlNode)xml.DocumentElement;
        XmlNode commonNode = node.SelectSingleNode("/blabla/att");
        commonNode.Attributes["List"].Value = value;
    }

GetCommonNode 工作正常并返回我的值。 SetCommonNode 不会改变我的价值。 也许我需要在更改后保存这个文件?

【问题讨论】:

    标签: c# .net xml wcf xmldocument


    【解决方案1】:

    如前所述,您似乎缺少 XML 文档保存方法调用。
    您应该能够通过添加以下内容来解决此问题:

    xml.Save(path);
    

    以下链接提供了更多详细信息:
    http://support.microsoft.com/kb/301233

    【讨论】:

      猜你喜欢
      • 2019-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      • 2019-12-18
      • 2015-08-25
      相关资源
      最近更新 更多