简体   繁体   English

通过WCF servive更改XML节点属性值

[英]Change XML node attribute value via WCF servive

[ServiceContract]
public interface IParametersXMLService
{
    [OperationContract, XmlSerializerFormat]
    XmlNode GetCommonNode(string path);

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

Service implementation: 服务实施:

    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 works fine and returns my value. GetCommonNode可以正常工作并返回我的值。 SetCommonNode does not change my value. SetCommonNode不会更改我的值。 Maybe I need to save this file after change? 也许更改后需要保存此文件?

As indicated, you seem to be missing the XML Document save method call. 如所示,您似乎缺少XML Document保存方法调用。
You should be able to resolve the issue by adding the following: 您应该可以通过添加以下内容来解决此问题:

xml.Save(path);

The following link provides additional details: 以下链接提供了更多详细信息:
http://support.microsoft.com/kb/301233 http://support.microsoft.com/kb/301233

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM