如题,项目中有一个可能需要对网站注册协议进行灵活配置的需求,很多配置都使用序列化方式保存到了xml 中.当使用xml序列化对诸如网站协议进行配置保存时,发生了问题。 换行丢失了.虽然这是意料中的问题,却也让我头疼了几天。
在http://geekswithblogs.net/cmartin/archive/2005/11/30/61705.aspx 中关于 Serializing A String Within a CDATA Element 的文章中提供一个不错的解决方法。 现在我对其进行了部分修改优化,使用起来会方便一些。






















































































































使用如下方式创建序列化类库(配置类)































测试代码




























生成的xml文档:


<?xml version="1.0"?>
<CDataTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Agreement><![CDATA[
本服务协议内容包括协议正文及所有xxx网已经发布的或将来可能发布的各类规则。所有规则为协议不可分割的一部分,与协议正文具有同等法律效力。
在本服务协议中没有以“规则”字样表示的链接文字所指示的文件不属于本服务协议的组成部分,而是其它内容的协议或有关参考数据,与本协议没有法律上的直接关系。
用户在使用xxx网提供的各项服务的同时,承诺接受并遵守各项相关规则的规定。xxx网有权根据需要不时地制定、修改本协议或各类规则,如本协议有任何变更,xxx网将在网站上刊载公告,通知予用户。如用户不同意相关变更,必须停止使用“服务”。经修订的协议一经在xxx网公布后,立即自动生效。各类规则会在发布后生效,亦成为本协议的一部分。登录或继续使用“服务”将表示用户接受经修订的协议。除另行明确声明外,任何使“服务”范围扩大或功能增强的新内容均受本协议约束。
用户确认本服务协议后,本服务协议即在用户和xxx网之间产生法律效力。请用户务必在注册之前认真阅读全部服务协议内容,如有任何疑问,可向xxx网咨询。 1)无论用户事实上是否在注册之前认真阅读了本服务协议,只要用户点击协议正本下方的“确认”按钮并按照xxx网注册程序成功注册为用户,用户的行为仍然表示其同意并签署了本服务协议。 2)本协议不涉及用户与xxx网其它用户之间因网上交易而产生的法律关系及法律纠纷。
二、 定义
xxx网上交易平台:有关xxx网上交易平台上的术语或图示的含义,详见xxx网帮助。
用户及用户注册:用户必须是具备完全民事行为能力的自然人,或者是具有合法经营资格的实体组织。无民事行为能力人、限制民事行为能力人以及无经营或特定经营资格的组织不当注册为xxx网用户或超过其民事权利或行为能力范围从事交易的,其与xxx网之间的服务协议自始无效,xxx网一经发现,有权立即注销该用户,并追究其使用xxx网“服务”的一切法律责任。用户注册是指用户登陆xxx网,并按要求填写相关信息并确认同意履行相关用户协议的过程。用户因进行交易、获取有偿服务或接触xxx网服务器而发生的所有应纳税赋,以及一切硬件、软件、服务及其它方面的费用均由用户负责支付。xxx网站仅作为交易地点。xxx网仅作为用户物色交易对象,就货物和服务的交易进行协商,以及获取各类与贸易相关的服务的地点。xxx网不能控制交易所涉及的物品的质量、安全或合法性,商贸信息的真实性或准确性,以及交易方履行其在贸易协议项下的各项义务的能力。xxx网并不作为买家或是卖家的身份参与买卖行为的本身。xxx网提醒用户应该通过自己的谨慎判断确定登录物品及相关信息的真实性、合法性和有效性。
三、 用户权利和义务:
用户有权利拥有自己在xxx网的用户名及交易密码,并有权利使用自己的用户名及 密码随时登陆xxx网交易平台。用户不得以任何形式擅自转让或授权他人使用自己的xxx网用户名;
]]></Agreement>
</CDataTest>