how to append node with attributes after an node in XML + C# [modified]
-
hello every one I am tried to update an XML file but its not working according to my requirement. I have to create a new child node below the parent node with matching condition --where attribute of e.g is equal to 3 (comes from query string). Also new child have different attributes except . So I have to create a with setting new values of all the attributes. This is the structure of XML file ----------------------------------------------------------------- ........all have same structure c1f13323-209b-4b0e-ad8d-d34f64d34c28 C:\Documents and Settings\Login Subhash\Desktop\iframe.html New Link Help 2007-10-25T11:47:10.515625+05:30 SUBHASH\Login Subhash C:\Documents and Settings\Login Subhash\Desktop\main.html Adding New Html Help 3 C:\Documents and Settings\Login Subhash\Desktop\iframe.html New Link Help ........all have same structure And this is my sample code ----------------------------------------------------------------- strXMLFile = strAlbumPath + "\\" + strAlbumName + ".linkinfo.xml"; XmlDocument doc = new XmlDocument(); doc.Load(strXMLFile); FileStream findata = new FileStream(strXMLFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); objDataSet.ReadXml(findata); findata.Close(); //int intRefId = Convert.ToInt32(Request.QueryString["RefId"]); int intRefId = 3; string strFilePath = FileUpload.PostedFile.FileName; string strXPath = "/LinkInformation/ScreensToSupport/ScreenToSupport/SupportItems/ScreenSupportItem[RefId='" + intRefId + "']"; XmlNode newParent = doc.SelectSingleNode(strXPath);//.ParentNode.NextSibling.ChildNodes;
-
hello every one I am tried to update an XML file but its not working according to my requirement. I have to create a new child node below the parent node with matching condition --where attribute of e.g is equal to 3 (comes from query string). Also new child have different attributes except . So I have to create a with setting new values of all the attributes. This is the structure of XML file ----------------------------------------------------------------- ........all have same structure c1f13323-209b-4b0e-ad8d-d34f64d34c28 C:\Documents and Settings\Login Subhash\Desktop\iframe.html New Link Help 2007-10-25T11:47:10.515625+05:30 SUBHASH\Login Subhash C:\Documents and Settings\Login Subhash\Desktop\main.html Adding New Html Help 3 C:\Documents and Settings\Login Subhash\Desktop\iframe.html New Link Help ........all have same structure And this is my sample code ----------------------------------------------------------------- strXMLFile = strAlbumPath + "\\" + strAlbumName + ".linkinfo.xml"; XmlDocument doc = new XmlDocument(); doc.Load(strXMLFile); FileStream findata = new FileStream(strXMLFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); objDataSet.ReadXml(findata); findata.Close(); //int intRefId = Convert.ToInt32(Request.QueryString["RefId"]); int intRefId = 3; string strFilePath = FileUpload.PostedFile.FileName; string strXPath = "/LinkInformation/ScreensToSupport/ScreenToSupport/SupportItems/ScreenSupportItem[RefId='" + intRefId + "']"; XmlNode newParent = doc.SelectSingleNode(strXPath);//.ParentNode.NextSibling.ChildNodes;
Vishnu Narayan Mishra wrote:
newRootParent.InsertAfter(newRootParent, newScreenToSupport);
As the error message explains, you are adding a node as a child of itself here. Read the MSDN documentation[^] on this method if you are unsure how to use it.
Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush