■ XmlNamespaceMapping 엘리먼트를 사용해 XML 네임스페이스를 바인딩하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <XmlNamespaceMappingCollection x:Key="XmlNamespaceMappingCollectionKey"> <XmlNamespaceMapping Prefix="dc" Uri="http://purl.org/dc/elements/1.1/" /> </XmlNamespaceMappingCollection> <XmlDataProvider x:Key="XmlDataProviderKey" XmlNamespaceManager="{StaticResource XmlNamespaceMappingCollectionKey}" XPath="rss/channel/item" Source="https://icodebroker.tistory.com/rss" /> <DataTemplate x:Key="DataTemplateKey"> <Border BorderThickness="1" BorderBrush="Gray"> <Grid 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, FallbackValue=''}" /> </Grid> </Border> </DataTemplate> </Window.Resources> <ListBox Margin="10" Background="Honeydew" ItemTemplate="{StaticResource DataTemplateKey}" ItemsSource="{Binding Source={StaticResource XmlDataProviderKey}}" /> </Window> |
※ XmlDataProvider 엘리먼트의 Source 속성에 기존 설정된 URL이 없어지면서 본인 블로그 RSS URL을 설정했는데 해당 데이터에는 dc:date 항목이 없다.