代码如下所示:StringBuilder builder = new StringBuilder();XmlWriterSettings settings = new XmlWriterSettings();settings.OmitXmlDeclaration = true;using (XmlWriter xmlWriter = XmlWriter.Create(builder, settings)){ XmlSerializer s = new XmlSerializer(objectToSerialize.GetType()); s.Serialize(xmlWriter, objectToSerialize);}生成的序列化文档包含名称空间,如下所示:<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns="urn:something"> ...</message>要删除xsi和xsd命名空间,我可以按照如何将对象序列化为XML而不获取xmlns =“...”的答案?。我希望我的消息标记为<message>(没有任何命名空间属性)。我怎样才能做到这一点?
3 回答
桃花长相依
TA贡献1860条经验 获得超8个赞
...
XmlSerializer s = new XmlSerializer(objectToSerialize.GetType());
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("","");
s.Serialize(xmlWriter, objectToSerialize, ns);
- 3 回答
- 0 关注
- 517 浏览
添加回答
举报
0/150
提交
取消