在.NET中生成的XML命名空间中删除 [英] Remove namespace from generated XML in .NET

查看:108
本文介绍了在.NET中生成的XML命名空间中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
XmlSerializer的:删除不必要的XSI和XSD命名空间

我生成使用XMLSerializer的一些XML标记,并与属性的类。此XML被发送到一个REST Web服务

I'm generating some XML using XMLSerializer and a class marked up with attributes. This XML is sent to a REST web service.

它产生下面的XML:

<?xml version="1.0" encoding="utf-8"?>
<person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <first-name>API</first-name>
  <last-name>TestPersonDeleteMe</last-name>
  <title>Delete me</title>
</person>



所有都会很好,但我使用的是不理解的东西架构的Web服务, 。抛出一个500错误

All would be well, except the web service I'm using doesn't understand the schema stuff and throws a 500 error.

有没有办法阻止XmlSerializer的加入'的xmlns:XSI =htt​​p://www.w3.org/ 2001 / XML模式实例的xmlns:XSD =?http://www.w3.org/2001/XMLSchema'的标签

Is there a way to stop XmlSerializer adding 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"' to the person tag?

推荐答案

如果您使用自定义序列试试这个

if you use custom serializer try this

XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);



然后加命名空间反对你的串行器。

then add namespaces object to your serializer.

这篇关于在.NET中生成的XML命名空间中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆