大家好,
我现在有一个xml配置文件,里面有如下的内容:<?xml version="1.0" encoding="utf-8" ?>
<Information>
<WebServicesURL>192.168.100.153</WebServicesURL>
</Information>假如,我现在有一个Webservice的url为:http://192.168.100.153/Mobile/Service.asmx;
我想把Mobile也添加到xml文件中。<?xml version="1.0" encoding="utf-8" ?>
<Information>
<WebServicesURL>192.168.100.153</WebServicesURL>
<MobileURL>Mobile</MobileURL>
</Information>那上面的红线的添加方式是否合适呢??
我现在有一个xml配置文件,里面有如下的内容:<?xml version="1.0" encoding="utf-8" ?>
<Information>
<WebServicesURL>192.168.100.153</WebServicesURL>
</Information>假如,我现在有一个Webservice的url为:http://192.168.100.153/Mobile/Service.asmx;
我想把Mobile也添加到xml文件中。<?xml version="1.0" encoding="utf-8" ?>
<Information>
<WebServicesURL>192.168.100.153</WebServicesURL>
<MobileURL>Mobile</MobileURL>
</Information>那上面的红线的添加方式是否合适呢??
public static void Insert(string path, string node, string element, string attribute, string value)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode xn = doc.SelectSingleNode(node);
if (element.Equals(""))
{
if (!attribute.Equals(""))
{
XmlElement xe = (XmlElement)xn;
xe.SetAttribute(attribute, value);
}
}
else
{
XmlElement xe = doc.CreateElement(element);
if (attribute.Equals(""))
{
xe.InnerText = value;
}
else
{
xe.SetAttribute(attribute, value);
}
xn.AppendChild(xe);
}
doc.Save(path);
}
catch { }
}是否适合根据需要