在XML序列化时去除默认命名空间xmlns:xsd和xmlns:xsi
摘 自: http://blog.csdn.net/fxhflower/article/details/7276820
可使用以下代码:
//Create our own namespaces for the output
XmlSerializerNamespaces ns = new XmlSerializerNamespaces ();
//Add an empty namespace and empty value
ns.Add ("", "");
//Create the serializer
XmlSerializer slz = new XmlSerializer (someType);
//Serialize the object with our own namespaces (notice the overload)
slz.Serialize (myXmlTextWriter, someObject, ns); 此外,在评论中还提到了去除开头的<?xml version="1.0" encoding="utf-8"?>的方法:
XmlWriterSettings settings = new XmlWriterSettings ();
// Remove the <?xml version="1.0" encoding="utf-8"?>
settings.OmitXmlDeclaration = true;
XmlWriter writer = XmlWriter.Create ("output_file_name.xml", settings); 另外,如果出现开头没有encoding="utf-8"时,应该使用:
XmlWriterSettings settings = new XmlWriterSettings ();
settings.Encoding = Encoding.UTF8;
XmlWriter writer = XmlWriter.Create ("output_file_name.xml", settings);
在XML序列化时去除默认命名空间xmlns:xsd和xmlns:xsi的更多相关文章
- .Net 序列化(去除默认命名空间,添加编码)
1.序列化注意事项 (1).Net 序列化是基于对象的.所以只有实例字段呗序列化.静态字段不在序列化之中. (2)枚举永远是可序列化的. 2.XML序列化时去除默认命名空间xmlns:xsd和xmln ...
- .NET(C#):XML序列化时派生类的处理
原文 www.cnblogs.com/mgen/archive/2011/12/03/2275014.html 目录 1. 针对基类的XmlSerializer序列化派生类 2. 类内成员是派生类的序 ...
- c# 中xml序列化时相同节点存入不同类型值
先上需要序列话的类定义: [System.Xml.Serialization.XmlIncludeAttribute(typeof(DescriptionType))] [System.CodeDom ...
- C# XML 去xmlns:xsd和xmlns:xsi属性
public static XElement WithoutNamespaces(this XElement element) { if (element == null) return null; ...
- Xml序列化去掉命名空间,去掉申明
#region 序列化 /// <summary> /// 序列化 /// </summary> /// <par ...
- [.net 面向对象程序设计进阶] (11) 序列化(Serialization)(三) 通过接口 IXmlSerializable 实现XML序列化 及 通用XML类
[.net 面向对象程序设计进阶] (11) 序列化(Serialization)(三) 通过接口 IXmlSerializable 实现XML序列化 及 通用XML类 本节导读:本节主要介绍通过序列 ...
- 【转】Xml序列化
XML序列化是将对象的公共属性和字段转换为XML格式,以便存储或传输的过程.反序列化则是从XML输出中重新创建原始状态的对象.XML序列化中最主要的类是XmlSerializer类.它的最重要的方法是 ...
- .net学习笔记---xml序列化
XML序列化是将对象的公共属性和字段转换为XML格式,以便存储或传输的过程.反序列化则是从XML输出中重新创建原始状态的对象.XML序列化中最主要的类是XmlSerializer类.它的最重要的方法是 ...
- 第五篇 -- Xml序列化
XML序列化是将对象的公共属性和字段转换为XML格式,以便存储或传输的过程.反序列化则是从XML输出中重新创建原始状态的对象.XML序列化中最主要的类是XmlSerializer类.它的最重要的方法是 ...
随机推荐
- 让Chrome可以修改字体
在chrome地址栏输入chrome://flags/ , 然后将"停用DirectWrite Windows"改为停用 , 这样自定义的字体就可以生效了.
- ylbtech-LanguageSamples-Struct(结构)
ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-Struct(结构) 1.A,示例(Sample) 返回顶部 “结构”示例 本示例演示结 ...
- JAVA用户数据输入
数据输入 首先需要导入扫描仪 然后声明扫描仪 输出输入提示 接收用户数据的数据 输出用户数据的数据 实例: import java.util.Scanner; //导入扫描仪 public class ...
- ppm与毫克/立方米怎么换算
ppm是溶液浓度(溶质质量分数)的一种表示方法,1升水溶液中有1毫克的溶质,g/m3或mg/L. 对于气体:,一百万体积的空气中所含污染物的体积数. 而按我国规定,特别是环保部门,则要求气体浓度以质量 ...
- poj 2109 Power of Cryptography
点击打开链接 Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16388 Ac ...
- [ZOJ 1005] Jugs (dfs倒水问题)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5 题目大意:给你6种操作,3个数a,b,n,代表我有两个杯子,第一个杯 ...
- Integer cache
View.findViewById采用深度遍历,找到第一个匹配的控件 Integer Cache public static void testIntegerCache() { Class cache ...
- Spark1.0源码编译
编译方式一:mavenexport MAVEN_OPTS="-Xmx2g -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=512m"m ...
- [转载]python中multiprocessing.pool函数介绍
原文地址:http://blog.sina.com.cn/s/blog_5fa432b40101kwpi.html 作者:龙峰 摘自:http://hi.baidu.com/xjtukanif/blo ...
- 【Unity Shaders】学习笔记——SurfaceShader(八)生成立方图
[Unity Shaders]学习笔记——SurfaceShader(八)生成立方图 转载请注明出处:http://www.cnblogs.com/-867259206/p/5630261.html ...