本帖最后由 lxcnn 于 2008-11-08 13:44:03 编辑

解决方案 »

  1.   

                    XmlDocument document = new XmlDocument();
                    XmlDeclaration declaration = document.CreateXmlDeclaration("1.0", "UTF-8", null);
                    document.AppendChild(declaration);                //根节点
                    XmlElement content = document.CreateElement("content");
                    document.AppendChild(content);                //title 节点
                    XmlElement title = document.CreateElement("title");
                    content.AppendChild(title);                XmlElement tCNT = document.CreateElement("CNT");
                    title.AppendChild(tCNT);
                    tCNT.InnerText = strTitle;                //text 节点
                    XmlElement text = document.CreateElement("text");
                    content.AppendChild(text);                text.InnerXml = strContent;
                    //XmlElement teCNT = document.CreateElement("CNT");
                    //text.AppendChild(teCNT);
                    //teCNT.InnerText = strContent;
                    //teCNT.InnerXml = strContent;
                    document.Save(strXmlName);    
      

  2.   

    <?xml version="1.0" encoding="UTF-8"?>
    <content>
      <title>
        <CNT>Angle Formed by Two&lt;br clear=all&gt;&amp;nbsp;Non-coplanar Lines</CNT>
      </title>
      <text>
        <txt>What is the angle formed by two non-coplanar lines? It is defined as the non-obtuse angle formed by any two coplanar lines which are parallel to the two non-coplanar lines, respectively.  </txt><txt>angle</txt><txt>parallel lines</txt><txt>  The angle can be found as follows: fix one of the non-coplanar lines and elevate a duplicate of the other non-coplanar line parallel to meet the fixed line. The non-obtuse angle formed in this way is defined as the angle formed by the two non-coplanar lines.  </txt></text>
    </content>
      

  3.   

    试试这个XmlDocument document = new XmlDocument(); 
                    XmlDeclaration declaration = document.CreateXmlDeclaration("1.0", "UTF-8", null); 
                    document.AppendChild(declaration);                 //根节点 
                    XmlElement content = document.CreateElement("content"); 
                   
                    //title 节点 
                    XmlElement title = document.CreateElement("title"); 
                    content.AppendChild(title);                 XmlElement tCNT = document.CreateElement("CNT"); 
                    title.AppendChild(tCNT); 
                    tCNT.InnerText = strTitle;                 //text 节点 
                    XmlElement text = document.CreateElement("text"); 
                    content.AppendChild(text);                 text.InnerXml = strContent; 
     document.AppendChild(content);                 //XmlElement teCNT = document.CreateElement("CNT"); 
                    //text.AppendChild(teCNT); 
                    //teCNT.InnerText = strContent; 
                    //teCNT.InnerXml = strContent; 
                    document.Save(strXmlName);    
      

  4.   

    楼主的问题应该是楼主在插入内容当中原本就没有换行字符,所以当插入到XML当中的时候,他们默认认为一行进行处理。
    在需要换行的地方强制加入换行字符\n
    参考  XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("test.xml"));
            XmlNode newNode = doc.CreateNode(XmlNodeType.Element, "TT1", null);
            //newNode.InnerText = "The angle can be found as follows: fix one of the non-coplanar lines and elevate a duplicate of the other non-coplanar line parallel to meet the fixed line. The non-obtuse angle formed in this way is defined as the angle formed by the two non-coplanar lines. ";
            newNode.InnerText = "The angle can be found as follows: fix one of the non-coplanar lines and elevate a duplicate of the other non-coplanar line parallel to meet the fixed line.\n The non-obtuse angle formed in this way is defined as the angle formed by the two non-coplanar lines. ";        XmlNode obj = doc.SelectSingleNode("//excludeRC");
            obj.AppendChild(newNode);
            doc.Save(Server.MapPath("test.xml"));
        }