Modifier

Partager via


XmlAttributeAttribute.Namespace Property

Definition

Gets or sets the XML namespace of the XML attribute.

public:
 property System::String ^ Namespace { System::String ^ get(); void set(System::String ^ value); };
public string Namespace { get; set; }
public string? Namespace { get; set; }
member this.Namespace : string with get, set
Public Property Namespace As String

Property Value

The XML namespace of the XML attribute.

Examples

The following example applies the XmlAttributeAttribute to two fields contained in a class. The example sets the Namespace property for each attribute to a value different from the member identifier.

public ref class Car
{
public:

   [XmlAttributeAttribute(Namespace="Make")]
   String^ MakerName;

   [XmlAttributeAttribute(Namespace="Model")]
   String^ ModelName;
};
public class Car
{
   [XmlAttribute(Namespace = "Make")]
   public string MakerName;

   [XmlAttribute(Namespace = "Model")]
   public string ModelName;
}
Public Class Car
    <XmlAttribute(Namespace := "Make")> _
    Public MakerName As String    

    <XmlAttribute(Namespace := "Model")> _
    Public ModelName As String
End Class

Remarks

The Namespace property conforms to the http://www.w3.org specification Namespaces in XML.

To create namespaces that are associated with prefixes, you must create an XmlSerializerNamespaces object that contains the namespaces and prefixes used in the XML document. The namespace you set for each XmlAttributeAttribute must match one of the namespaces in the XmlSerializerNamespaces object. When the XmlSerializer generates the XML code, it correctly prefixes each attribute name.

Applies to