日期:2014-05-18  浏览次数:20949 次

请教一个c#写XML换行的问题
有一个XML文件,其中有一段是这样的
XML code

  <Device
    Facility="SMIC-F8"
    Technology="1118C014.N7NOW"
    WaferSize="300"
    EdgeExclusion="3000"
    NotchExclusionWidth="12500"
    NotchExclusionHeight="3500"
    WaferConfigFile="SMIC-F8_1118C014.N7NOW_F781537B_20111104000000_wfcfg.xml"
    CreateDate="20111104000000"
    Orientation="270"
    ReticleOrientation="0"
    />



用IE打开看各个属性是不换行的,但是用UE等编辑器打开是换行的
请问这个该如何实现?
谢谢!
PS. 开发环境:VS2010

------解决方案--------------------
用XmlWriter来控制换行的问题:
C# code

            XDocument doc = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement("Root",
                    new XAttribute("attr1", "value"),
                    new XAttribute("attr2", "value")
                    )
                );
            Console.WriteLine(doc);

            using (StreamWriter sw = new StreamWriter(@"D:\test.xml")) {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                settings.IndentChars = "  ";
                settings.NewLineOnAttributes = true;
                XmlWriter xmlWriter = XmlWriter.Create(sw, settings);
                doc.Save(xmlWriter);
                xmlWriter.Close();
            }