C# omitting nodes XML

R10

New Member
I have an XML document that is written with this algorithm:\[code\]public XMLmethod(){string[] nodes = { "node1", "node2", "node3" }; //etc etcXmlTextWriter writer= new XmlTextWriter("file.xml", Encoding.UTF8);writer.WriteStartDocument();writer.WriteStartElement("root");foreach (string node in nodes){writer.WriteStartElement(s);writer.WriteEndElement();XMLmethod()}writer.WriteEndElement();writer.WriteEndDocument();}\[/code\]The above is a simplified version. However, I want to be able to filter out some nodes before printing them to xml.For example:\[code\]<root> <node1> <node2> </node2> <node3> </node3> </node1><root>\[/code\]Say I wanted to filter \[code\]<node1> </node1>\[/code\]So it would look like this\[code\]<root> <node2></node2> <node3></node3></root>\[/code\]so it would still want to print the children \[code\]<node2></node2>\[/code\] and \[code\]<node3></node3>\[/code\]I thought about using an if statement like:\[code\]foreach (string node in nodes){if(node == "node1"){}else{writer.WriteStartElement(node);writer.WriteEndElement();XMLmethod()}}\[/code\]this successfully doesn't print \[code\]<node1>/<node1>\[/code\] but it also stops it from printing the children nodes. Any idea how I can go about doing this?
 
Back
Top