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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
if you use custom serializer try this
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty);
then add namespaces object to your serializer.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0