简体   繁体   中英

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. SetCommonNode does not change my value. Maybe I need to save this file after change?

As indicated, you seem to be missing the XML Document save method call.
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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