Create or replace node in an XML without root in C# -


After

I have an XML file like this:

  & lt; Some & gt; .... & lt; / Some & gt; & Lt; Other & gt; .... & lt; / One & gt; & Lt; Other & gt; ... & lt; / Other & gt;  

And this XML file is not a fundamental element (I know this is an incorrect XML format).

I need to create or replace an existing node in this XML, but I can not work with XDocument or XmlDocument Because they need a basic element and I can not add a basic element to this XML because I have more code changing applications (Windows Forms Applications) in my options to do this? Edit 1: Using @chridam sample I have this method but it replaces whole XML ... what do I need to change?

  public void ReEscribirNodoXML (string pathXml, string nodoName, string nodeContent) {if (File.Exists (pathXml)) {XmlValidatingReader vr = new XmlValidatingReader (pathXml, XmlNodeType.Element, null); While (vr.Read ()) Debug.WriteLine ("NodeType: {0} nodename: {1}", vr.NodeType, vr.Name); XmlWriterSettings Settings = New XmlWriterSettings (); Settings.Indent = true; Settings.OmitXmlDeclaration = True; Settings.NewLineOnAttributes = true; Var Author = XmlWriter.Create (pathXml, settings); Writer.WriteStartElement (nodoName); Writer.WriteRaw (nodeContent); Writer.WriteEndElement (); Writer.flush (); } And (new exception throwing ("I # error");}}  

one just can work together, using Xdocument by supplying a framework When you finish the settings

being here piece, a change, a new node is added and is going out a piece:

  var piece = @ "the & lt; a & gt; ABC & lt; / a & gt; & lt; a & Gt; DEFT & lt; / other & gt; & lt; Other & gt; GIT & lt; / other & gt; "; Var x Doc = XDocument.Parse ( "& lt; TempRoot & gt;" + piece + "& lt; / TempRoot & gt;"); XDoc.Descendants ( "other"). First (). Value = "Jbrboki"; XDoc .Root.Add (new XElement ( "Omega", "Man")); Var fragOut = string.Join (environment. new, xDoc.Root .Elements (). Select (ele = & gt; ele.ToString ()) ); Kansolkprkash line (Frogot); / * Print the & lt; a & gt; ABC & lt; / a & gt; & LT; other & gt; Jabberwocky & lt; / a & gt; & LT ; Other & gt; GHI & lt; / Other & gt; & lt; Omega & gt; Man & lt; / Omega & gt; * /  

Comments