OK、コードのセクションを XML にシリアライズしようとして少し問題が発生しています。次のような XML が必要です。
<document DataObject="Y">
<data Attribute="Y"><![CDATA[01/01/2013]]></data>
</document>
CData タグを使用して xml を生成できますが、要素の属性を把握できません。
クラスの例を次に示します。
Public Class document
<XmlAttribute()> _
Public AMSDataObject As String = "Y"
Private _Data As DateTime
<XmlIgnore()> _
Public Property VarData
Get
Return _Data
End Get
Set(value)
_Data = value
End Set
End Property
Public Property Data As XmlCDataSection
Get
Return GetCData(Me._Data)
End Get
Set(ByVal value As XmlCDataSection)
Me._Data = value.Value
End Set
End Property
Private Function GetCData(ByVal value As String) As XmlCDataSection
Static doc As New XmlDataDocument()
Static cdata As XmlCDataSection = doc.CreateCDataSection(value)
Return (cdata)
End Function
End Class
助言がありますか。これらすべてに対処する簡単な方法があると確信しています。
また、ここにserlizationクラスがあります。
Private Sub WriteXMLToFile(ByRef file As AMS_DOC_XML_EXPORT_FILE, ByVal filename As String)
Dim ser As New XmlSerializer(GetType(AMS_DOC_XML_EXPORT_FILE))
Dim writer As New StreamWriter(filename)
'Remove Default name spaces
Dim xns As New XmlSerializerNamespaces
xns.Add(String.Empty, String.Empty)
'Remove XML Declaration in front of file
Dim xmlsettings As New XmlWriterSettings
xmlsettings.OmitXmlDeclaration = True
xmlsettings.Indent = True
Using xmlwriter As XmlWriter = xmlwriter.Create(writer, xmlsettings)
ser.Serialize(xmlwriter, file, xns)
End Using
writer.Close()
End Sub
ありがとう