[英]XmlSerializer : Remove xmlns:xsd but keep xmlns:xsi
I'm using this method to generate an XML : 我正在使用此方法生成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();
}
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">
. 结果是我有这样一行
<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: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"
。
How can I do that ? 我怎样才能做到这一点 ?
Thanks for your help ! 谢谢你的帮助 !
您可以尝试以下代码来删除xmlns条目:
var ns = new XmlSerializerNamespaces(); ns.Add("", "");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.