XmlTypeMapping.TypeName Property
.NET Framework 3.5
Gets the type name of the mapped object.
Assembly: System.Xml (in System.Xml.dll)
The type name is the class name of the mapped object.
You can also see the fully qualified name by examining the TypeFullName property.
using System; using System.IO; using System.Xml.Serialization; using System.Collections; using System.Xml; using System.Text; namespace Company{ [SoapType("TheGroup", "http://www.cohowinery.com")] public class Group { public string GroupName; public Thing[] Things; [SoapElement(DataType = "language")] public string Lang = "en"; [SoapElement(DataType = "integer")] public string MyNumber; [SoapElement(DataType = "duration")] public string ReDate = "8/31/01"; } public class Thing{ public string ThingName; } public class Test { public static void Main() { Test t = new Test(); t.GetMap("MyMap.xml"); } public void GetMap(string filename){ // Create an XmlSerializer instance. XmlTypeMapping map = new SoapReflectionImporter().ImportTypeMapping(typeof(Group)); Console.WriteLine("ElementName: " + map.ElementName); Console.WriteLine("Namespace: " + map.Namespace); Console.WriteLine("TypeFullName: " + map.TypeFullName); Console.WriteLine("TypeName: " + map.TypeName); XmlSerializer ser = new XmlSerializer(map); Group xGroup= new Group(); xGroup.GroupName= "MyCar"; xGroup.MyNumber= 5454.ToString(); xGroup.Things = new Thing[]{new Thing(), new Thing()}; // To write the outer wrapper, use an XmlTextWriter. XmlTextWriter writer = new XmlTextWriter(filename, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartElement("wrapper"); ser.Serialize(writer, xGroup); writer.WriteEndElement(); writer.Close(); } } }
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
using namespace System::Collections;
using namespace System::Xml;
using namespace System::Text;
__gc public class Thing
{
public:
String* ThingName;
};
[SoapType(S"TheGroup", S"http://www.cohowinery.com")]
__gc public class Group
{
public:
String* GroupName;
Thing * Things[];
[SoapElement(DataType = S"language")]
static String* Lang = S"en";
[SoapElement(DataType = S"integer")]
String* MyNumber;
[SoapElement(DataType = S"duration")]
static String* ReDate = S"8/31/01";
};
void GetMap(String* filename)
{
// Create an XmlSerializer instance.
SoapReflectionImporter *sri = new SoapReflectionImporter();
XmlTypeMapping *map = sri->ImportTypeMapping(__typeof(Group) );
Console::WriteLine(S"ElementName: {0}", map -> ElementName);
Console::WriteLine(S"Namespace: {0}", map -> Namespace);
Console::WriteLine(S"TypeFullName: {0}", map -> TypeFullName);
Console::WriteLine(S"TypeName: {0}", map -> TypeName);
XmlSerializer* ser = new XmlSerializer(map);
Group* xGroup = new Group();
xGroup -> GroupName= S"MyCar";
xGroup -> MyNumber= S"5454";
xGroup -> Things = new Thing*[2]; // {new Thing(), new Thing()};
xGroup->Things[0] = new Thing();
xGroup->Things[1] = new Thing();
// To write the outer wrapper, use an XmlTextWriter.
XmlTextWriter* writer = new XmlTextWriter(filename, Encoding::UTF8);
writer -> Formatting = Formatting::Indented;
writer -> WriteStartElement(S"wrapper");
ser -> Serialize(writer, xGroup);
writer -> WriteEndElement();
writer -> Close();
}
int main()
{
GetMap(S"MyMap.xml");
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.