【问题标题】:XmlSerializer : Remove xmlns:xsd but keep xmlns:xsiXmlSerializer :删除 xmlns:xsd 但保留 xmlns:xsi
【发布时间】:2016-11-19 04:15:31
【问题描述】:

我正在使用这种方法来生成 XML :

using (MemoryStream msRes = new MemoryStream())
        using (StreamWriter objStreamWriter = new StreamWriter(msRes))
        using (XmlWriter xw = XmlWriter.Create(objStreamWriter, new XmlWriterSettings() { Indent = true, IndentChars = String.Empty }))
        {
            XmlSerializer serializer = new XmlSerializer(doc.GetType());
            serializer.Serialize(xw, doc);
            return msRes.ToArray();
        }

结果是我有这种行<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02">。 我想删除属性xmlns:xsd="http://www.w3.org/2001/XMLSchema",但保留xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"

我该怎么做?

感谢您的帮助!

【问题讨论】:

标签: c# xml serialization xsd


【解决方案1】:

您可以尝试以下代码来删除 xmlns 条目:

var ns = new XmlSerializerNamespaces(); ns.Add("", "");

【讨论】:

  • 谢谢,但它会删除所有 xlmns 条目,我只想删除 xmlns:xsd 条目。
猜你喜欢
  • 2018-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-29
  • 2019-10-27
  • 2011-05-13
  • 1970-01-01
相关资源
最近更新 更多