zoukankan      html  css  js  c++  java
  • 在XML序列化时去除默认命名空间xmlns:xsd和xmlns:xsi

    //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);

  • 相关阅读:
    POJ 2388
    HDU 6152
    POJ 3085
    C语言字符数组回顾
    ZOJ 2480
    SQL学习(1)初学实验:SQL Server基本配置及基本操作
    Kali Linux入坑之基本配置(2018.1)
    C学习笔记(逗号表达式)
    C学习笔记(自增)
    forEach()&map()区别
  • 原文地址:https://www.cnblogs.com/smilekiss/p/4449498.html
Copyright © 2011-2022 走看看