1
[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不会改变我的价值。也许我需要在更改后保存这个文件?

4

1 回答 1

2

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

xml.Save(path);

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

于 2013-10-25T17:45:53.440 回答