50532

How to PROPERLY remove xmln:xsi and xmlns:xsd from xml dictionary serialization

Question:

Question: I use a serializable dictionary class, found at <br /><a href="http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx" rel="nofollow">http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx</a><br /> , to serialize a dictionary.<br /> It works fine with the example class below.

<System.Xml.Serialization.XmlRoot("ccl")> _ Public Class ccl <System.Xml.Serialization.XmlElement("name")> _ Public xx As String = "" <System.Xml.Serialization.XmlElement("date")> _ Public yy As String = "" '<System.Xml.Serialization.XmlElement("adict")> _ 'Public ww As New SerializableDictionary(Of String, String) End Class

But it adds a,

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance AND xmlns:xsd="http://www.w3.org/2001/XMLSchema?

to the tag

Now I fixed it by changing the dictionary class to

Dim ns As System.Xml.Serialization.XmlSerializerNamespaces = New System.Xml.Serialization.XmlSerializerNamespaces() 'Add an empty namespace and empty value ns.Add("", "") If True Then valueSerializer.Serialize(writer, value, ns) Else valueSerializer.Serialize(writer, value) End If

which removes those attributes.

But that also means it does not write them if I specify them. How can I add those two empty namespaces to the class using attributes ?

I changed it to

<System.Xml.Serialization.XmlRoot("ccl", Namespace:="")>

but that doesn't seem to work.

Answer1:

Here is the code I use to serialize to my object o

XmlSerializerNamespaces XSN = new XmlSerializerNamespaces(); XSN.Add("", ""); XmlWriterSettings XWS = new XmlWriterSettings(); XWS.OmitXmlDeclaration = true; StringBuilder XmlStr = new StringBuilder(); XmlSerializer x = new XmlSerializer(o.GetType()); x.Serialize(XmlTextWriter.Create(XmlStr, XWS), o, XSN);

Recommend

  • In LISP is it possible to access a function's form?
  • Clozure Common Lisp - TCP Socket Programming - Sending a Reply
  • Appending to the result of a “loop-collect” in Lisp
  • HTTP2 / SPDY Push-Stream Verification: How to Test?
  • phpseclib gives me a strange erros
  • LB_SETTABSTOPS does not appear to affect a CheckedListBox
  • How parse xml using jaxb
  • How to config WebService to return ArrayList instead of Array?
  • Deserialize XML in a WP8 Application
  • selenium scripts
  • Will VB.NET automatically generate ComClass attribute and guids?
  • SQL multiple SELECT query with xmlagg function- Data not pulled in the required fashion
  • Date format change angular 2
  • Thread 1: EXC_BAD_ACCESS ( code=2,address=0x8) Error c++
  • Can't run Appium tests on iOS 10 on real device
  • date: illegal option — d, Find difference between two dates
  • OAuth and the YouTube API
  • Adding directive inside the directive programatically
  • Get localized short date pattern as String?
  • How to pass nginx proxy url for socket
  • Illegal mix of collations for operation for date/time comparison
  • Release, debug version and Authorization Google?
  • Akka Routing: Reply's send to router ends up as dead letters
  • AT Commands to Send SMS not working in Windows 8.1
  • Cannot Parse HTML Data Using Android / JSOUP
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Hits per day in Google Big Query
  • JTable with a ScrollPane misbehaving
  • Java static initializers and reflection
  • apache spark aggregate function using min value
  • unknown Exception android
  • Sorting a 2D array using the second column C++
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • failed to connect to specific WiFi in android programmatically
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • Conditional In-Line CSS for IE and Others?
  • How can I use threading to 'tick' a timer to be accessed by other threads?