Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. how to append node with attributes after an node in XML + C# [modified]

how to append node with attributes after an node in XML + C# [modified]

Scheduled Pinned Locked Moved XML / XSL
csharphtmldatabasexmlhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vishnu Narayan Mishra
    wrote on last edited by
    #1

    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;

    P 1 Reply Last reply
    0
    • V Vishnu Narayan Mishra

      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;

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups