问题描述
问题:
我使用了一个序列化的字典类,在
的
,序列化。字典
它正常工作与下面的例子类
Question:I use a serializable dictionary class, found at
http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx
, to serialize a dictionary.
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
但它增加了一个血淋淋的
的xmlns:XSI =http://www.w3.org/2001/XMLSchema-instance和xmlns:XSD =http://www.w3.org / 2001 / XML模式?
的标签
But it adds a bloodyxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance AND xmlns:xsd="http://www.w3.org/2001/XMLSchema?to the tag
现在我改变字典类
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
这消除这些属性。
但是,这也意味着如果我指定他们不会写。
我如何添加使用属性这两个空的命名空间的类?
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 ?
我改成了
<System.Xml.Serialization.XmlRoot("ccl", Namespace:="")> _
但似乎并没有工作。
but that doesn't seem to work.
推荐答案
下面是我使用序列化到我的对象的代码0
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);
这篇关于从XML序列化的词典XSD:如何正确地删除xmln:XSI和xmlns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!