Files
docs-desktop/dotnet-desktop-guide/framework/wpf/data/how-to-use-xml-namespaces-in-data-binding.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

31 lines
1.7 KiB
Markdown

---
title: "How to: Use XML Namespaces in Data Binding"
ms.date: "03/30/2017"
helpviewer_keywords:
- "XML [WPF], namespaces"
- "data binding [WPF], XML namespaces"
- "namespaces [WPF], XML"
ms.assetid: a47c832f-dc84-48f2-96d5-cde18fc4284b
---
# How to: Use XML Namespaces in Data Binding
## Example
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 <xref:System.Windows.Data.XmlNamespaceMapping> element to map the namespace to a <xref:System.Windows.Data.XmlNamespaceMapping.Prefix%2A>, as in the following example. You can then use the <xref:System.Windows.Data.XmlNamespaceMapping.Prefix%2A> to refer to the XML namespace. The <xref:System.Windows.Controls.ListBox> in this example displays the *title* and *dc:date* of each *item*.
[!code-xaml[XmlnsBindSnippet#XmlNamespaceMapping](~/samples/snippets/csharp/VS_Snippets_Wpf/XmlnsBindSnippet/CS/Window1.xaml#xmlnamespacemapping)]
Note that the <xref:System.Windows.Data.XmlNamespaceMapping.Prefix%2A> 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 <xref:System.Windows.Data.XmlNamespaceMapping> element also works with inline XML or XML data in an embedded file.
## See also
- [Bind to XML Data Using an XMLDataProvider and XPath Queries](how-to-bind-to-xml-data-using-an-xmldataprovider-and-xpath-queries.md)
- [Data Binding Overview](/dotnet/desktop-wpf/data/data-binding-overview)
- [How-to Topics](data-binding-how-to-topics.md)