Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove namespace from generated XML in .NET [duplicate]

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?

like image 897
Richard Garside Avatar asked Jun 01 '10 14:06

Richard Garside


1 Answers

if you use custom serializer try this

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

then add namespaces object to your serializer.

like image 84
Arseny Avatar answered Nov 20 '22 14:11

Arseny