XmlTypeAttribute Constructors
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Initialiseert een nieuw exemplaar van de XmlTypeAttribute klasse.
Overloads
| Name | Description |
|---|---|
| XmlTypeAttribute() |
Initialiseert een nieuw exemplaar van de XmlTypeAttribute klasse. |
| XmlTypeAttribute(String) |
Initialiseert een nieuw exemplaar van de XmlTypeAttribute klasse en geeft de naam van het XML-type op. |
XmlTypeAttribute()
- Bron:
- XmlTypeAttribute.cs
- Bron:
- XmlTypeAttribute.cs
- Bron:
- XmlTypeAttribute.cs
- Bron:
- XmlTypeAttribute.cs
- Bron:
- XmlTypeAttribute.cs
Initialiseert een nieuw exemplaar van de XmlTypeAttribute klasse.
public:
XmlTypeAttribute();
public XmlTypeAttribute();
Public Sub New ()
Voorbeelden
In het volgende voorbeeld worden twee exemplaren van de XmlTypeAttribute klasse gemaakt die worden gebruikt om de serialisatie van de twee klassen te overschrijven.
using System;
using System.IO;
using System.Xml.Serialization;
public class Person
{
public string personName;
public Address address;
}
public class Address
{
public string state;
public string zip;
}
public class PersonTypeAttribute
{
public static void Main()
{
PersonTypeAttribute myPersonTypeAttribute= new PersonTypeAttribute();
myPersonTypeAttribute.SerializeObject("XmlType.xml");
}
public XmlSerializer CreateOverrider()
{
XmlAttributeOverrides personOverride = new XmlAttributeOverrides();
XmlAttributes personAttributes = new XmlAttributes();
XmlTypeAttribute personType = new XmlTypeAttribute();
personType.TypeName = "Employee";
personType.Namespace = "http://www.microsoft.com";
personAttributes.XmlType = personType;
XmlAttributes addressAttributes = new XmlAttributes();
// Create 'XmlTypeAttribute' with 'TypeName' as an argument.
XmlTypeAttribute addressType = new XmlTypeAttribute("Address");
addressType.Namespace = "http://www.microsoft.com";
addressAttributes.XmlType=addressType;
personOverride.Add(typeof(Person) ,personAttributes);
personOverride.Add(typeof(Address),addressAttributes);
XmlSerializer myXmlSerializer = new XmlSerializer
(typeof(Person), personOverride);
return myXmlSerializer;
}
public void SerializeObject(string filename)
{
XmlSerializer myXmlSerializer = CreateOverrider();
Address myAddress = new Address();
myAddress.state="AAA";
myAddress.zip="11111";
Person myPerson = new Person();
myPerson.personName="Smith";
myPerson.address=myAddress;
// Serialize to a file.
TextWriter writer = new StreamWriter(filename);
myXmlSerializer.Serialize(writer, myPerson);
}
}
Imports System.IO
Imports System.Xml.Serialization
Public Class Person
Public personName As String
Public address As Address
End Class
Public Class Address
Public state As String
Public zip As String
End Class
Public Class PersonTypeAttribute
Public Shared Sub Main()
Dim myPersonTypeAttribute As New PersonTypeAttribute()
myPersonTypeAttribute.SerializeObject("XmlType.xml")
End Sub
Public Function CreateOverrider() As XmlSerializer
Dim personOverride As New XmlAttributeOverrides()
Dim personAttributes As New XmlAttributes()
Dim personType As New XmlTypeAttribute()
personType.TypeName = "Employee"
personType.Namespace = "http://www.microsoft.com"
personAttributes.XmlType = personType
Dim addressAttributes As New XmlAttributes()
' Create 'XmlTypeAttribute' with 'TypeName' as an argument.
Dim addressType As New XmlTypeAttribute("Address")
addressType.Namespace = "http://www.microsoft.com"
addressAttributes.XmlType = addressType
personOverride.Add(GetType(Person), personAttributes)
personOverride.Add(GetType(Address), addressAttributes)
Dim myXmlSerializer As New XmlSerializer(GetType(Person), personOverride)
Return myXmlSerializer
End Function
Public Sub SerializeObject(filename As String)
Dim myXmlSerializer As XmlSerializer = CreateOverrider()
Dim myAddress As New Address()
myAddress.state = "AAA"
myAddress.zip = "11111"
Dim myPerson As New Person()
myPerson.personName = "Smith"
myPerson.address = myAddress
' Serialize to a file.
Dim writer = New StreamWriter(filename)
myXmlSerializer.Serialize(writer, myPerson)
End Sub
End Class
Van toepassing op
XmlTypeAttribute(String)
- Bron:
- XmlTypeAttribute.cs
- Bron:
- XmlTypeAttribute.cs
- Bron:
- XmlTypeAttribute.cs
- Bron:
- XmlTypeAttribute.cs
- Bron:
- XmlTypeAttribute.cs
Initialiseert een nieuw exemplaar van de XmlTypeAttribute klasse en geeft de naam van het XML-type op.
public:
XmlTypeAttribute(System::String ^ typeName);
public XmlTypeAttribute(string typeName);
public XmlTypeAttribute(string? typeName);
new System.Xml.Serialization.XmlTypeAttribute : string -> System.Xml.Serialization.XmlTypeAttribute
Public Sub New (typeName As String)
Parameters
- typeName
- String
De naam van het XML-type dat wordt XmlSerializer gegenereerd wanneer het klasse-exemplaar wordt geserialiseerd (en herkent wanneer het klasse-exemplaar wordt gedeserialiseerd).
Voorbeelden
In het volgende voorbeeld worden twee exemplaren van de XmlTypeAttribute klasse gemaakt die worden gebruikt om de serialisatie van de twee klassen te overschrijven.
using System;
using System.IO;
using System.Xml.Serialization;
public class Person
{
public string personName;
public Address address;
}
public class Address
{
public string state;
public string zip;
}
public class PersonTypeAttribute
{
public static void Main()
{
PersonTypeAttribute myPersonTypeAttribute= new PersonTypeAttribute();
myPersonTypeAttribute.SerializeObject("XmlType.xml");
}
public XmlSerializer CreateOverrider()
{
XmlAttributeOverrides personOverride = new XmlAttributeOverrides();
XmlAttributes personAttributes = new XmlAttributes();
XmlTypeAttribute personType = new XmlTypeAttribute();
personType.TypeName = "Employee";
personType.Namespace = "http://www.microsoft.com";
personAttributes.XmlType = personType;
XmlAttributes addressAttributes = new XmlAttributes();
// Create 'XmlTypeAttribute' with 'TypeName' as an argument.
XmlTypeAttribute addressType = new XmlTypeAttribute("Address");
addressType.Namespace = "http://www.microsoft.com";
addressAttributes.XmlType=addressType;
personOverride.Add(typeof(Person) ,personAttributes);
personOverride.Add(typeof(Address),addressAttributes);
XmlSerializer myXmlSerializer = new XmlSerializer
(typeof(Person), personOverride);
return myXmlSerializer;
}
public void SerializeObject(string filename)
{
XmlSerializer myXmlSerializer = CreateOverrider();
Address myAddress = new Address();
myAddress.state="AAA";
myAddress.zip="11111";
Person myPerson = new Person();
myPerson.personName="Smith";
myPerson.address=myAddress;
// Serialize to a file.
TextWriter writer = new StreamWriter(filename);
myXmlSerializer.Serialize(writer, myPerson);
}
}
Imports System.IO
Imports System.Xml.Serialization
Public Class Person
Public personName As String
Public address As Address
End Class
Public Class Address
Public state As String
Public zip As String
End Class
Public Class PersonTypeAttribute
Public Shared Sub Main()
Dim myPersonTypeAttribute As New PersonTypeAttribute()
myPersonTypeAttribute.SerializeObject("XmlType.xml")
End Sub
Public Function CreateOverrider() As XmlSerializer
Dim personOverride As New XmlAttributeOverrides()
Dim personAttributes As New XmlAttributes()
Dim personType As New XmlTypeAttribute()
personType.TypeName = "Employee"
personType.Namespace = "http://www.microsoft.com"
personAttributes.XmlType = personType
Dim addressAttributes As New XmlAttributes()
' Create 'XmlTypeAttribute' with 'TypeName' as an argument.
Dim addressType As New XmlTypeAttribute("Address")
addressType.Namespace = "http://www.microsoft.com"
addressAttributes.XmlType = addressType
personOverride.Add(GetType(Person), personAttributes)
personOverride.Add(GetType(Address), addressAttributes)
Dim myXmlSerializer As New XmlSerializer(GetType(Person), personOverride)
Return myXmlSerializer
End Function
Public Sub SerializeObject(filename As String)
Dim myXmlSerializer As XmlSerializer = CreateOverrider()
Dim myAddress As New Address()
myAddress.state = "AAA"
myAddress.zip = "11111"
Dim myPerson As New Person()
myPerson.personName = "Smith"
myPerson.address = myAddress
' Serialize to a file.
Dim writer = New StreamWriter(filename)
myXmlSerializer.Serialize(writer, myPerson)
End Sub
End Class
Opmerkingen
Pas de XmlTypeAttribute klasse toe om de naamruimte van het XML-type, de naam van het XML-type op te geven en of het type moet worden opgenomen in het XML-schemadocument. Als u de resultaten wilt zien van het instellen van de eigenschappen van de XmlTypeAttribute klasse, compileert u uw toepassing als een uitvoerbaar bestand of DLL en geeft u het resulterende bestand door aan het XML Schema Definition Tool (Xsd.exe). Het hulpprogramma schrijft het schema, inclusief de typedefinitie.