看风者

我们就象水中的一介浮萍,在风中飘来飘去.

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

  2004-12-29, 04:09 下午
feng 离线,最后访问时间: 2004-12-29 16:09:12 feng


发帖数前50位
等级: 新手上路
注册: 2004-11-03
发贴: 2
问个dataset写xml的问题,高手进来看下。

一个dataset,想写成xml格式。

Ds.WriteXml(Path);

问题是ds中列Content我保存的是html数据,回写的时候都转换成了<>之类的了。

我现在想写成的xml还是保存成html内容,也就是说不进行转换,该怎么操作:

这是用WriteXml生成的数据。

<?xml version="1.0" standalone="yes"?>
<Text>
  <Reply>
    <ID>670006</ID>
    <Link>&lt;br&gt;&lt;Br&gt;</Link>
  </Reply>
</Text>

这是我希望生成的数据:
<?xml version="1.0" standalone="yes"?>
<Text>
  <Reply>
    <ID>670006</ID>
    <Link><![CDATA[<br><Br>]]></Link>
  </Reply>
</Text>

那dataset写xml的时候,该如何操作,如何指定某列用CDATA方式写入???


IP 地址: 已记录    
  2004-12-30, 11:55 上午
Lion 离线,最后访问时间: 2005-3-21 9:26:30 Lion


发帖数前10位
等级: 新手上路
注册: 2004-10-31
发贴: 48
Re: 问个dataset写xml的问题,高手进来看下。
void test()
  {
   System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
   doc.LoadXml("<root>"+
    "  <pagesetting>"+
    "    <Landscape>false</Landscape>"+
    "    <paperkind>A4</paperkind>"+
    "  </pagesetting>"+
    "  <reporttable>"+
    "  </reporttable>"+
    "</root>");
   System.Xml.XmlComment newComment;
   newComment = doc.CreateComment("RemotePrint XML document");
 
   //Create a xml declaration.
   System.Xml.XmlDeclaration xmldecl;
   xmldecl = doc.CreateXmlDeclaration("1.0",null,null);
   xmldecl.Encoding="GB2312";
   xmldecl.Standalone="yes";
  
   System.Xml.XmlElement root = doc.DocumentElement;
   doc.InsertBefore(xmldecl, root);
   doc.InsertBefore(newComment, root);
   //
   System.Xml.XmlNode reporttable = doc["root"]["reporttable"];
   reporttable.AppendChild(doc.CreateCDataSection("<br />测试<span style=\"color:blue;\">数据</span><br />"));
   doc.Save(Server.MapPath("test.xml"));
  }

-------------------------------------------------
<?xml version="1.0" encoding="GB2312" standalone="yes"?>
<!--RemotePrint XML document-->
<root>
  <pagesetting>
    <Landscape>false</Landscape>
    <paperkind>A4</paperkind>
  </pagesetting>
  <reporttable><![CDATA[<br />测试<span style="color:blue;">数据</span><br />]]></reporttable>
</root>

posted on 2005-03-21 11:21  看风者  阅读(980)  评论(0编辑  收藏  举报