XmlAttributeAttribute.Namespace 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 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 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性質符合規範Namespaces in XML。http://www.w3.org
要建立與前綴相關的命名空間,必須建立 XmlSerializerNamespaces 包含 XML 文件中使用的命名空間與前綴的物件。 你為每個 XmlAttributeAttribute 命名空間設定的名稱空間必須與物件 XmlSerializerNamespaces 中的某一個命名空間相符。 當 產生 XmlSerializer XML 程式碼時,會正確地在每個屬性名稱前綴。