XmlSerializer : 删除 xmlns:xsd 但保留 xmlns:xsi [英] XmlSerializer : Remove xmlns:xsd but keep xmlns:xsi
问题描述
我正在使用此方法生成 XML :
I'm using this method to generate an 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"
.
The result is that I have this sort of line <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">
.
I'd like to remove the attribute xmlns:xsd="http://www.w3.org/2001/XMLSchema"
but keep xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"
.
我该怎么做?
感谢您的帮助!
推荐答案
您可以尝试以下代码来删除 xmlns 条目:
You could try the below code to remove the xmlns entries:
var ns = new XmlSerializerNamespaces(); ns.Add("", "");
这篇关于XmlSerializer : 删除 xmlns:xsd 但保留 xmlns:xsi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!