开发者

Remove namespace from generated XML in .NET [duplicate]

This question already has answers here: Closed 12 years ago. 开发者_如何转开发

Possible Duplicate:

XmlSerializer: remove unnecessary xsi and xsd namespaces

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

It generates the following 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>

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

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜