DX


Resource interpreted as Document but transferred with MIME type application/xml: "http://api.tradeglobals.com/api/affiliate/queryproduct?affiliateId=51194842&key=d94cbcf6-0855-405c-b617-f8e5dbf1a892&skus=&language=en".


How to Serialize objects to XML without namespace and declaration Recently I had to recreate an old service module from an old website, which outputted XML. There was a requirement to meet a certain format, which was without xml namespaces (XMLNS) and declarations. Our project team decided to use object serialization and I quickly ran into the problem that the .Net serializers likes to output namespaces and declarations. There is however a way to avoid this Here is how I did it: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 public string ToXml() { //this avoids xml document declaration XmlWriterSettings settings = new XmlWriterSettings() { Indent = false, OmitXmlDeclaration = true }; var stream = new MemoryStream(); using (XmlWriter xw = XmlWriter.Create(stream, settings)) { //this avoids xml namespace declaration XmlSerializerNamespaces ns = new XmlSerializerNamespaces( new[] { XmlQualifiedName.Empty }); XmlSerializer x = new XmlSerializer(GetType(), ""); x.Serialize(xw, this, ns); } return Encoding.UTF8.GetString(stream.ToArray()); } Enjoy!