C# 通过WCF服务更改XML节点属性值
服务实施:C# 通过WCF服务更改XML节点属性值,c#,.net,xml,wcf,xmldocument,C#,.net,Xml,Wcf,Xmldocument,服务实施: [ServiceContract] public interface IParametersXMLService { [OperationContract, XmlSerializerFormat] XmlNode GetCommonNode(string path); [OperationContract, XmlSerializerFormat] void SetCommonNode(string path, string value); }
[ServiceContract]
public interface IParametersXMLService
{
[OperationContract, XmlSerializerFormat]
XmlNode GetCommonNode(string path);
[OperationContract, XmlSerializerFormat]
void SetCommonNode(string path, string value);
}
GetCommonNode
工作正常并返回我的值。
SetCommonNode
不会更改我的值。
更改后可能需要保存此文件?如前所述,您似乎缺少XML文档保存方法调用。
您应该能够通过添加以下内容来解决此问题:
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;
}
以下链接提供了其他详细信息:xml.Save(path);