本文整理匯總了VB.NET中System.Xml.Serialization.XmlAnyAttributeAttribute.XmlAnyAttributeAttribute構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET XmlAnyAttributeAttribute構造函數的具體用法?VB.NET XmlAnyAttributeAttribute怎麽用?VB.NET XmlAnyAttributeAttribute使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在類System.Xml.Serialization.XmlAnyAttributeAttribute
的用法示例。
在下文中一共展示了XmlAnyAttributeAttribute構造函數的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Group
' 導入命名空間
Imports System.IO
Imports System.Xml.Serialization
Imports System.Xml
Public Class Group
' The Things array will be used to collect all unknown
' attributes found when deserializing.
public GroupName As String
public Things() As XmlAttribute
End Class
Public Class Test
Shared Sub Main()
Dim t As Test = New Test()
t.DeserializeObject("UnknownAttributes.xml")
End Sub
Private Sub SerializeObject(filename As String)
Dim ser As XmlSerializer = New XmlSerializer(GetType (Group))
Dim writer As TextWriter = New StreamWriter(filename)
Dim g As Group = New Group()
g.GroupName = "MyGroup"
ser.Serialize(writer, g)
writer.Close()
End Sub
Private Sub DeserializeObject(filename As String)
' Use the CreateOverrideSerializer to return an instance
' of the XmlSerializer customized for overrides.
Dim ser As XmlSerializer = CreateOverrideSerializer()
' 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()
Console.WriteLine(g.GroupName)
Console.WriteLine(g.Things.Length)
Dim xAtt As XmlAttribute
for each xAtt in g.Things
Console.WriteLine(xAtt.Name & ": " & xAtt.InnerXml)
Next
End Sub
Private Function CreateOverrideSerializer() As XmlSerializer
' Override the Things field to capture all
' unknown XML attributes.
Dim myAnyAttribute As XmlAnyAttributeAttribute = _
New XmlAnyAttributeAttribute()
Dim xOverride As XmlAttributeOverrides = _
New XmlAttributeOverrides()
Dim xAtts As XmlAttributes = New XmlAttributes()
xAtts.XmlAnyAttribute=myAnyAttribute
xOverride.Add(GetType(Group), "Things", xAtts)
return New XmlSerializer(GetType(Group) , xOverride)
End Function
End Class