zoukankan      html  css  js  c++  java
  • 在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);
  • 相关阅读:
    [JZOJ 5788] 餐馆
    [JZOJ 5778] 没有硝烟的战争
    problems_scala
    好迷茫,好迷茫啊
    公布下我的数据库操作层
    关于数据库大并发量(未完成)
    关于http协议头
    管理心得体会
    数据库表分区
    公共的Json操作类
  • 原文地址:https://www.cnblogs.com/wuyifu/p/4132381.html
Copyright © 2011-2022 走看看