C# 在现有XML中插入新的子节点
大家好。我想请求有关我的代码的帮助。我这里有一个包含以下内容的XML文档C# 在现有XML中插入新的子节点,c#,asp.net,xml,C#,Asp.net,Xml,大家好。我想请求有关我的代码的帮助。我这里有一个包含以下内容的XML文档 <?xml version="1.0" encoding="utf-8" ?> <TechnicalReport> <Data quantity = "2" description ="myDesc" findings = "none" actiontaken = "none" /> </TechnicalReport> 请帮忙 尝试在方法末尾添
<?xml version="1.0" encoding="utf-8" ?>
<TechnicalReport>
<Data quantity = "2" description ="myDesc" findings = "none" actiontaken = "none" />
</TechnicalReport>
请帮忙 尝试在方法末尾添加以下内容:
originalXml.Save(Server.MapPath("xmlTechReportDetails.xml"));
我想是因为你没有保存文件。这就是为什么不保留您的更改。而不是此代码:
//Create the node name Technical Report
XmlNode TechReport = originalXml.SelectSingleNode("TechnicalReport");
使用此代码
XmlNodeList nodeList = originalXml.GetElementsByTagName("connectionStrings");
您在哪里设置
XMLDataSouece
?它已经在设计时设置好了。我认为您必须使用Data
属性获取将控件绑定到的XML,修改它并将其设回。将XmlTechReportDetails.Data
设为字符串,将其解析为XML
,修改并将其设回字符串。
//Create the node name Technical Report
XmlNode TechReport = originalXml.SelectSingleNode("TechnicalReport");
XmlNodeList nodeList = originalXml.GetElementsByTagName("connectionStrings");