110,536
社区成员
发帖
与我相关
我的任务
分享
private static void UpdateXml(string path)
{
if (File.Exists(path))
{
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode ulac = doc.DocumentElement.SelectSingleNode("//ULAC");
if (ulac != null)
{
XmlNode newNode = doc.CreateElement("moi");
XmlAttribute attr = doc.CreateAttribute("xsi", "type", "");
attr.Value = "ULAC";
newNode.Attributes.Append(attr);
newNode.InnerXml = ulac.InnerXml;
ulac.ParentNode.ReplaceChild(newNode, ulac);
}
XmlNode usac = doc.DocumentElement.SelectSingleNode("//USAC");
if (usac != null)
{
XmlNode newNode = doc.CreateElement("moi");
XmlAttribute attr = doc.CreateAttribute("xsi", "type", "");
attr.Value = "USAC";
newNode.Attributes.Append(attr);
newNode.InnerXml = usac.InnerXml;
usac.ParentNode.ReplaceChild(newNode, usac);
}
doc.Save(path);
}
}
private static void UpdateXml(string path)
{
if (File.Exists(path))
{
XmlDocument doc = new XmlDocument();
doc.Load("test.xml");
XmlNode ulac = doc.DocumentElement.SelectSingleNode("//ULAC");
if (ulac != null)
{
XmlNode newNode = doc.CreateElement("moi");
XmlAttribute attr = doc.CreateAttribute("xsi", "type", "");
attr.Value = "ULAC";
newNode.Attributes.Append(attr);
newNode.InnerXml = ulac.InnerXml;
ulac.ParentNode.ReplaceChild(newNode, ulac);
}
XmlNode usac = doc.DocumentElement.SelectSingleNode("//USAC");
if (usac != null)
{
XmlNode newNode = doc.CreateElement("moi");
XmlAttribute attr = doc.CreateAttribute("xsi", "type", "");
attr.Value = "USAC";
newNode.Attributes.Append(attr);
newNode.InnerXml = usac.InnerXml;
usac.ParentNode.ReplaceChild(newNode, usac);
}
doc.Save(path);
}
}