我哪里出错了???
我有一个带有 OppDetails 作为标签的 xml 文件,如下所示
<OppDetails>
<OMID>245414</OMID>
<ClientName>Best Buy</ClientName>
<OppName>International Rate Card</OppName>
<CTALinkType>AO,IO,MC,TC</CTALinkType>
</OppDetails>
</OppFact>
现在我尝试向其中添加另一个元素,但在 AppendChild 方法中出现错误,请帮助
XmlNode rootNode = xmlDoc.SelectSingleNode("OppDetails");
XmlElement xmlEle = xmlDoc.CreateElement("CTAStartDate");
xmlEle.InnerText = ExcelUtility.GetCTAStartDate();
rootNode.AppendChild(xmlEle);
xmlDoc.Save("C:\\test.xml");
最佳答案
XmlElement xmlEle = xmlDoc.DocumentElement["OppDetails"];
XmlElement eleNew = xmlDoc.CreateElement("CTAStartDate");
eleNew.InnerText = ExcelUtility.GetCTAStartDate();
xmlEle.AppendChild(eleNew);
xmlDoc.Save("C:\\test.xml");
关于c# - 将元素添加到现有 XML 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2665069/