Export (0) Print
Expand All

XmlNamespaceMappingCollection Class

Represents a collection of XmlNamespaceMapping objects.

Namespace: System.Windows.Data
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[LocalizabilityAttribute(LocalizationCategory.NeverLocalize)] 
public class XmlNamespaceMappingCollection : XmlNamespaceManager, ICollection<XmlNamespaceMapping>, IEnumerable<XmlNamespaceMapping>, 
	IEnumerable, IAddChild
/** @attribute LocalizabilityAttribute(LocalizationCategory.NeverLocalize) */ 
public class XmlNamespaceMappingCollection extends XmlNamespaceManager implements ICollection<XmlNamespaceMapping>, 
	IEnumerable<XmlNamespaceMapping>, IEnumerable, IAddChild
LocalizabilityAttribute(LocalizationCategory.NeverLocalize) 
public class XmlNamespaceMappingCollection extends XmlNamespaceManager implements ICollection<XmlNamespaceMapping>, 
	IEnumerable<XmlNamespaceMapping>, IEnumerable, IAddChild
<XmlNamespaceMappingCollection .../>

The XmlNamespaceMapping class provides a mapping between the namespace specified in your XMLbinding source and a prefix you specify that you can use in Extensible Application Markup Language (XAML).

This example shows how to handle namespaces specified in your XMLbinding 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.

For the complete example, see Binding Using XML Namespaces Sample.

System.Object
   System.Xml.XmlNamespaceManager
    System.Windows.Data.XmlNamespaceMappingCollection

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft