XmlTypeMapping.XsdTypeNamespace Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the XML namespace of the mapped object.

Namespace:   System.Xml.Serialization
Assembly:  System.Xml (in System.Xml.dll)

public string XsdTypeNamespace { get; }

Property Value

Type: System.String

The XML namespace of the mapped object. The default is an empty string ("").

To set a namespace name of an object, apply a SoapTypeAttribute to the class, and set the Namespace property to a new value.

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();


   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;
      ser.Serialize(writer, xGroup);

.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top