就直接存这样的字符串“<html></html&gt”会把&变为&?

解决方案 »

  1.   

    try:XmlCDataSection cdata=xd.CreateCDataSection(article.Value.ToString());
    XmlElement body=xd.CreateElement("body");
    body.AppendChild(cdata);
    xerecord.AppendChild(body);
      

  2.   

    public class Book
    {
       public string title;   static void Main()
       {
          Book introToVCS = new Book();
          introToVCS.title = "Intro to Visual CSharp";
          System.Xml.Serialization.XmlSerializer writer = 
             new System.Xml.Serialization.XmlSerializer(introToVCS.GetType());
          System.IO.StreamWriter file =
             new System.IO.StreamWriter("c:\\IntroToVCS.xml");      writer.Serialize(file, introToVCS);
          file.Close();
       }
    }
      

  3.   

    我上面的代码不行吗,在CDATA节点中可以保存任何字符,不信可以用IE打开下面的XML看看<?xml version="1.0"?>
    <root>
      <body>
        <![CDATA[asdfq< & html&amp;gt;& ]]>
      </body>
    </root>
      

  4.   

    XmlDocument doc=new XmlDocument();
    doc.Load("xmlfile");XmlCDataSection cdata=doc.CreateCDataSection(article.Value.ToString());
    XmlElement body=doc.CreateElement("body");
    body.AppendChild(cdata);
    doc.AppendChild(body);doc.Svae("xmlfile");
      

  5.   

    名称“cdata”在类或命名空间“FriendsReunion.sendarticle”中不存在
      

  6.   

    下面是MSDN中的代码,你看看
    using System;
    using System.IO;
    using System.Xml;public class Sample
    {
      public static void Main()
      {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                    "<title>Pride And Prejudice</title>" +
                    "</book>");    //Create a CData section.
        XmlCDataSection CData;
        CData = doc.CreateCDataSection("All Jane Austen novels 25% off starting 3/23!");        //Add the new node to the document.
        XmlElement root = doc.DocumentElement;
        root.AppendChild(CData);  
            
        Console.WriteLine("Display the modified XML...");        
        doc.Save(Console.Out);
      }
    }
      

  7.   

    <body><![CDATA[&lt;html&gt;&lt;/html&gt;&lt;&gt;]]></body>5555
    存进去的变成这样了.
      

  8.   

    你本来不是要保存lt;html&gt;&lt;/html这些字符吗!!!
      

  9.   

    是呀.
    可是现在lt;html&gt;&lt;/html  谢谢在了CDATA里边了,等用XSL转换出来的时候,它就变成了&lt;html&gt;&lt;/html&gt;&lt;&gt;   ....
    郁闷...大家再帮忙呀...
      

  10.   

    那你直接保存<html></html>到CDATA节点就行啦,不要保存为&lt;html&gt;&lt;/html&gt;。看看你的XSL
      

  11.   

    <xsl:value-of select="//body" disable-output-escaping="yes"></xsl:value-of>
    即可
      

  12.   

    我现在是这么做的:
    XmlCDataSection cdata=xd.CreateCDataSection(article.Value.ToString().Trim());
    XmlElement body=xd.CreateElement("body");
    body.AppendChild(cdata);
    xerecord.AppendChild(body);其中
    article.Value.ToString().Trim()的内容是<html></html>
    当我执行完后,它在XML文件中写入了
    <body><![CDATA[&lt;html&gt;&lt;/html&gt;&lt;&gt;&lt;&gt;&lt;&gt;]]></body>
    等我再用XSL显示出来的时候,它就直接把CDATA中的内容显示出来了.没有把&lt;和&gt;转换成 < 和>  ...
    再帮忙.谢谢.
      

  13.   

    XSL:<?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
        <html>
        <head></head>
        <body>
           <xsl:value-of select="//body" disable-output-escaping="yes"></xsl:value-of>
        </body>
        </html>
      </xsl:template>
    </xsl:stylesheet>
    ------------------
    XML:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="123.xsl"?>
    <root>
      <body><![CDATA[
         &lt;html&gt;&lt;/html&gt;&lt;&gt;&lt;&gt;&lt;&gt;
            ]]>
      </body>
    </root>
      

  14.   

    <%@ Page ValidateRequest="false" Language="C#" Debug="true"%>
    <Script Language="C#" Runat="Server">
    public void Button1_Click(Object sender,EventArgs e)
     {
      System.Xml.XmlDocument x = new System.Xml.XmlDocument();
      x.LoadXml("<root/>");
      Response.Write(Server.HtmlEncode(x.OuterXml)); 
    System.Xml.XmlCDataSection body=x.CreateCDataSection(article.Value);
    x.DocumentElement.AppendChild(body);
    Response.Write("<hr>");
    Response.Write(Server.HtmlEncode(x.OuterXml));
     }
    </Script>
    <html>
    <head><title>HtmlButton控件</title></head>
    <body>
    <form runat="server">
    <textarea id=article runat=server><html></html></textarea>
    <button id="button1" runat="server" OnServerClick="Button1_Click">提交</button>
    </form>
    </center>
    </body>
    </html>
      

  15.   

    看看你的XSL文件,可能有些地方不同而没注意!!!
      

  16.   

    太谢谢BearRui(孤熊 | 爱情!它把我给忘了!)  和   net_lover(孟子E章) 
    谢谢.
    散分.:)