如果没有人能帮我解决,那问题就得搁置到暑假了
思考赐予新生,时间在于定义
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace test___XML { class Program { static void Main(String[] args) { XmlTextWriter writer = new XmlTextWriter("Tree.xml", null); writer.Formatting = Formatting.Indented; writer.Indentation = 3; writer.WriteStartDocument(); writer.WriteComment("Created by TonyDeng @ " + DateTime.Now.ToString()); writer.WriteStartElement("Root"); writer.WriteStartElement("Node11"); writer.WriteAttributeString("id", "3"); writer.WriteStartElement("LNode21"); writer.WriteAttributeString("id", "2"); writer.WriteStartElement("LNode31"); writer.WriteAttributeString("id", "7"); writer.WriteEndElement(); // 关闭LNode31 writer.WriteStartElement("RNode32"); writer.WriteAttributeString("id", "6"); writer.WriteEndElement(); // 关闭LNode31 writer.WriteEndElement(); // 关闭LNode21 writer.WriteStartElement("RNode22"); writer.WriteAttributeString("id", "5"); writer.WriteEndElement(); writer.WriteEndElement(); // 关闭Node11 writer.WriteEndElement(); // 关闭Root writer.Close(); } } }
<?xml version="1.0"?> <!--Created by TonyDeng @ 2014/6/12 21:38:14--> <Root> <Node11 id="3"> <LNode21 id="2"> <LNode31 id="7" /> <RNode32 id="6" /> </LNode21> <RNode22 id="5" /> </Node11> </Root>