12

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?

Community
  • 1
  • 1
Richard Garside
  • 87,839
  • 11
  • 80
  • 93

1 Answers1

21

if you use custom serializer try this

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

then add namespaces object to your serializer.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Arseny
  • 7,251
  • 4
  • 37
  • 52