XmlNamespaceMapping Class
Declares a mapping between a uniform resource identifier (URI) and a prefix.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
The XmlNamespaceMapping type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | XmlNamespaceMapping() | Initializes a new instance of the XmlNamespaceMapping class. |
![]() | XmlNamespaceMapping(String, Uri) | Initializes a new instance of the XmlNamespaceMapping class with the specified prefix and uniform resource identifier (URI). |
| Name | Description | |
|---|---|---|
![]() | Equals | Returns a value that indicates whether this XmlNamespaceMapping is equivalent to the specified instance. (Overrides Object::Equals(Object).) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Returns the hash code for this XmlNamespaceMapping. (Overrides Object::GetHashCode().) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() ![]() | Equality | Performs equality comparison by value. |
![]() ![]() | Inequality | Performs inequality comparison by value. |
| Name | Description | |
|---|---|---|
![]() ![]() | ISupportInitialize::BeginInit | This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. |
![]() ![]() | ISupportInitialize::EndInit | This member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. |
To declare a mapping between a URI and a prefix, create an XmlNamespaceMapping class and add it to an XmlNamespaceMappingCollection object that is used as the XmlNamespaceManager for a binding.
This example shows how to handle namespaces specified in your XML binding source.
If your XML data has the following XML namespace definition:
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
You can use the XmlNamespaceMapping element to map the namespace to a Prefix, as in the following example. You can then use the Prefix to refer to the XML namespace. The ListBox in this example displays the title and dc:date of each item.
<StackPanel.Resources> <XmlNamespaceMappingCollection x:Key="mapping"> <XmlNamespaceMapping Uri="http://purl.org/dc/elements/1.1/" Prefix="dc" /> </XmlNamespaceMappingCollection> <XmlDataProvider Source="http://msdn.microsoft.com/subscriptions/rss.xml" XmlNamespaceManager="{StaticResource mapping}" XPath="rss/channel/item" x:Key="provider"/> <DataTemplate x:Key="dataTemplate"> <Border BorderThickness="1" BorderBrush="Gray"> <Grid Width="600" Height="50"> <Grid.RowDefinitions> <RowDefinition Height="25"/> <RowDefinition Height="25"/> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Text="{Binding XPath=title}" /> <TextBlock Grid.Row="1" Text="{Binding XPath=dc:date}" /> </Grid> </Border> </DataTemplate> </StackPanel.Resources> <ListBox Width="600" Height="600" Background="Honeydew" ItemsSource="{Binding Source={StaticResource provider}}" ItemTemplate="{StaticResource dataTemplate}"/>
Note that the Prefix you specify does not have to match the one used in the XML source; if the prefix changes in the XML source your mapping still works.
In this particular example, the XML data comes from a web service, but the XmlNamespaceMapping element also works with inline XML or XML data in an embedded file.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
