Language

XmlNamespaceDeclarationsAttribute Class

Definition

Specifies that the target property, parameter, return value, or class member contains prefixes associated with namespaces that are used within an XML document.

public ref class XmlNamespaceDeclarationsAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, AllowMultiple=false)]
public class XmlNamespaceDeclarationsAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue)]
public class XmlNamespaceDeclarationsAttribute : Attribute
[]
type XmlNamespaceDeclarationsAttribute = class
    inherit Attribute
[]
type XmlNamespaceDeclarationsAttribute = class
    inherit Attribute
Public Class XmlNamespaceDeclarationsAttribute
Inherits Attribute
Inheritance
XmlNamespaceDeclarationsAttribute
Attributes

Remarks

The XmlNamespaceDeclarationsAttribute attribute can only be applied once in a class to a field or property that returns an XmlSerializerNamespaces object.

The XmlNamespaceDeclarationsAttribute allows you to store the prefixes, and the associated namespaces, used in an XML document. For example, one common usage of the attribute is to store XPath data, as it is defined by the World Wide Web Consortium document named XML Language (XPath) Version 1.0. In brief, an XPath is a string that contains many namespace prefixes and local names, along with some other syntax.

The XPath language allows for the association of a prefix with a path, and using the prefix within the XML document. For example, the following XML document named "select" contains a prefix ("cal") associated with a specific URI (http://www.cohowinery.com/calendar/). The element contains an attribute named "path" that contains the XPath.


' Visual Basic
Imports System
Imports System.IO
Imports System.Xml.Serialization
 _
Public Class SelectPath
    _
   Public xpath As String
    _
   public xmlns As XmlSerializerNamespaces
End Class
Public Class Test
   Public Shared Sub Main()
      Dim mySelect As SelectPath = New SelectPath()
      mySelect.xpath = "myNS:ref/@common:y"
      mySelect.xmlns = New XmlSerializerNamespaces()
      mySelect.xmlns.Add("MyNS", "myNS.tempuri.org")
      mySelect.xmlns.Add("common", "common.tempuri.org")
      Dim ser As XmlSerializer = New XmlSerializer(mySelect.GetType)
      ser.Serialize(Console.Out, mySelect)
   End Sub
End Class
'Output:
' 
'