Export (0) Print
Expand All

XmlNamespaceMapping Class

Declares a mapping between a uniform resource identifier (URI) and a prefix.

System::Object
  System.Windows.Data::XmlNamespaceMapping

Namespace:  System.Windows.Data
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public ref class XmlNamespaceMapping : ISupportInitialize
<XmlNamespaceMapping .../>

The XmlNamespaceMapping type exposes the following members.

  NameDescription
Public methodXmlNamespaceMapping()Initializes a new instance of the XmlNamespaceMapping class.
Public methodXmlNamespaceMapping(String, Uri)Initializes a new instance of the XmlNamespaceMapping class with the specified prefix and uniform resource identifier (URI).
Top

  NameDescription
Public propertyPrefixGets or sets the prefix to use in Extensible Application Markup Language (XAML).
Public propertyUriGets or sets the Uri of the namespace for which to create a mapping.
Top

  NameDescription
Public methodEqualsReturns a value that indicates whether this XmlNamespaceMapping is equivalent to the specified instance. (Overrides Object::Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeReturns the hash code for this XmlNamespaceMapping. (Overrides Object::GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public operatorStatic memberEqualityPerforms equality comparison by value.
Public operatorStatic memberInequalityPerforms inequality comparison by value.
Top

  NameDescription
Explicit interface implemetationPrivate methodISupportInitialize::BeginInitThis member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.
Explicit interface implemetationPrivate methodISupportInitialize::EndInitThis member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.
Top

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.

.NET Framework

Supported in: 4.6, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft