dataProvider = new XmlDataProvider(); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(@"F:\Work\Samples\WPF\XML Binding Samples\tCustomers2.xml"); dataProvider.Document = doc; dataProvider.XPath = "DocumentElement"; XAML
<DataGrid x:Name="dgXml" DataContext="{Binding DataProvider}" ItemsSource="{Binding XPath=tCustomers}" AutoGenerateColumns="False" Grid.Row="1"> <DataGrid.Columns> <DataGridTextColumn IsReadOnly="True" Header="CustomerId" Binding="{Binding XPath=CustomerId/text()}" Width="*"/> <DataGridTextColumn Header="Customer Name" Binding="{Binding XPath=CustomerName/text()}" Width="*"/> <DataGridTextColumn Header="Customer Address" Binding="{Binding XPath=Address/text()}" Width="*"/> </DataGrid.Columns> </DataGrid>
<NewDataSet> <tCustomers> <CustomerId>1</CustomerId> <CustomerName>Customer1</CustomerName> <Address>asdf</Address> <BranchId>1</BranchId> </tCustomers> <tCustomers> <CustomerId>2</CustomerId> <CustomerName>Customer2</CustomerName> <Address>kgh</Address> <BranchId>1</BranchId> </tCustomers> <tCustomers> <CustomerId>3</CustomerId> <CustomerName>Customer3</CustomerName> <Address>kgh</Address> <BranchId>1</BranchId> </tCustomers> <tBranches> <BranchId>1</BranchId> <BranchName>Branch1</BranchName> <Address>Hydrebad</Address> </tBranches> <tBranches> <BranchId>2</BranchId> <BranchName>Branch2</BranchName> <Address>Bangalore</Address> </tBranches> </NewDataSet>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)