Remove special case indentation in XML files

patriarca

New Member
I want to modify a XML file but the tricky part is that the info I add should have minimal formatting. I have been searching for a while and I can't seem to find an answer. Here's what the XML looks currently (original):\[code\]<?xml version="1.0" encoding="utf-8"?><doe-jane> <name>Jane Doe</name> <contact>North PoleTel: (555) [email protected]</contact> <coveragelist> <company>Comp1</company> <company>Comp2</company> </coveragelist></doe-jane>\[/code\]It has to look like this:\[code\]<?xml version="1.0" encoding="utf-8"?><doe-jane> <name>Jane Doe</name> <contact>North PoleTel: (555) [email protected]</contact>--> // Change needs to happen from here on <--<coveragelist><company>Comp1</company><company>Comp2</company></coveragelist></doe-jane>\[/code\]Here's my code so far:\[code\]XmlDocument d = new XmlDocument();//XmlTextWriter wr = new XmlTextWriter(resAnXFile, Encoding.UTF8);//wr.Formatting = Formatting.None;d.Load(resAnXFile);XmlNode t = d.SelectSingleNode("//coveragelist");t.ParentNode.RemoveChild(t);// create CoverageList nodeXmlNode coverageListNode = d.CreateNode(XmlNodeType.Element, "coveragelist", null);foreach (var company in dataList){ // create company nodes XmlNode companyNode = d.CreateElement("company"); companyNode.InnerText = company.CompanyName.ToString(); coverageListNode.AppendChild(companyNode);}d.DocumentElement.AppendChild(coverageListNode);d.Save(resAnXFile);\[/code\]I've tried XMLTextWriter but I didn't have any luck. I really appreciate any help.Thank you in advance.
 
Back
Top