本文整理汇总了VB.NET中System.Xml.Serialization.XmlAnyAttributeAttribute类的典型用法代码示例。如果您正苦于以下问题:VB.NET XmlAnyAttributeAttribute类的具体用法?VB.NET XmlAnyAttributeAttribute怎么用?VB.NET XmlAnyAttributeAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XmlAnyAttributeAttribute类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Main
' 导入命名空间
Imports System.IO
Imports System.Xml.Serialization
Imports System.Xml
Public Class Group
Public GroupName As String
' The UnknownAttributes array will be used to collect all unknown
' attributes found when deserializing.
<XmlAnyAttribute> _
Public UnknownAttributes()As XmlAttribute
End Class
Public Class Test
Shared Sub Main()
Dim t As Test = New Test()
' Deserialize the file containing unknown attributes.
t.DeserializeObject("UnknownAttributes.xml")
End Sub
Private Sub DeserializeObject(filename As String)
Dim ser As XmlSerializer = New XmlSerializer(GetType(Group))
' A FileStream is needed to read the XML document.
Dim fs As FileStream = New FileStream(filename, FileMode.Open)
Dim g As Group = CType(ser.Deserialize(fs), Group)
fs.Close()
' Write out the data, including unknown attributes.
Console.WriteLine(g.GroupName)
Console.WriteLine("Number of unknown attributes: " & _
g.UnknownAttributes.Length)
Dim xAtt As XmlAttribute
for each xAtt in g.UnknownAttributes
Console.WriteLine(xAtt.Name & ": " & xAtt.InnerXml)
Next
' Serialize the object again with the attributes added.
Me.SerializeObject("AttributesAdded.xml",g)
End Sub
Private Sub SerializeObject(filename As String, g As object)
Dim ser As XmlSerializer = New XmlSerializer(GetType(Group))
DIm writer As TextWriter = New StreamWriter(filename)
ser.Serialize(writer, g)
writer.Close()
End Sub
End Class