I have a Name element "Dispute" and you want to add a new name for the Records element below the element.
Eg: The current Xml is in this format <NonFuel> <Desc>Non-Fuel</Desc> <Description> </Description> <Quantity/> <Amount/> <Additional/> <Dispute>0</Dispute> </NonFuel>
You must add a new item to the dispute.
<NonFuel> <Desc>Non-Fuel</Desc> <Description> </Description> <Quantity/> <Amount/> <Additional/> <Dispute>0</Dispute> <Records>01920</Records> </NonFuel>
Updated code: I tried to execute the following code, but get the error "The node link is not a child of this node":
XmlDocument xmlDoc=new XmlDocument() xmlDoc.LoadXml(recordDetails); XmlNodeList disputes = xmlDoc.GetElementsByTagName(disputeTagName); XmlNode root = xmlDoc.DocumentElement; foreach (XmlNode disputeTag in disputes) { XmlElement xmlRecordNo = xmlDoc.CreateElement("RecordNo"); xmlRecordNo.InnerText = Guid.NewGuid().ToString(); root.InsertAfter(xmlRecordNo, disputeTag); }
source share