XmlAttributeAttribute.Namespace 屬性

定義

取得或設定 XML 屬性的 XML 命名空間。

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

屬性值

XML 屬性的 XML 命名空間。

範例

下列範例會將 XmlAttributeAttribute 套用至 類別中包含的兩個欄位。 此範例會將 Namespace 每個屬性的屬性設定為與成員識別碼不同的值。

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

備註

屬性 Namespace 符合 http://www.w3.org 規格 Namespaces in XML

若要建立與前置詞相關聯的命名空間,您必須建立 XmlSerializerNamespaces 物件,其中包含 XML 檔中所使用的命名空間和前置詞。 您針對每個 XmlAttributeAttribute 設定的命名空間必須符合 物件中的 XmlSerializerNamespaces 其中一個命名空間。 XmlSerializer當 產生 XML 程式碼時,它會正確地在每個屬性名稱前面加上前置詞。

適用於