Appendix I. XPath

A program that binds to XML data uses XPath to determine which data is selected and which data is displayed. This appendix summarizes XPath and provides several examples.

XML in XAML

To include XML data inside XAML code, build an XmlDataProvider object containing an x:XData object. Inside that object, place well-formed XML data.

The XmlXDataProvider's XPath property gives the name of the data's root. Later code can refer to this root.

The following XAML code defines XML data used by later examples in this appendix. The root data element is named Customers. That element contains a series of Customer objects, each holding Order objects that contain Item objects. An Item object's value gives its description. Attributes give additional information about the various kinds of objects.

XML in XAML
<XmlDataProvider x:Key="customers" XPath="Customers"> <x:XData> <Customers xmlns=""> <Customer CustName="Bob Farkle"> <Order OrderDate="4/1/2010"> <Item Quantity="12" UnitPrice="0.10">Pencils</Item> <Item Quantity="3" UnitPrice="0.95">Notepad</Item> <Item Quantity="1" UnitPrice="3.99">Cookies, Dozen</Item> </Order> </Customer> <Customer CustName="Edwin Cumberbund"> <Order OrderDate="4/13/2010"> <Item Quantity="6" UnitPrice="0.10">Pencils</Item> <Item Quantity="6" UnitPrice="1.40">Green Tea</Item> <Item Quantity="1" UnitPrice="39.95">Book</Item> </Order> <Order OrderDate="5/1/2010"> <Item Quantity="1" ...

Get WPF Programmer's Reference: Windows Presentation Foundation with C# 2010 and .NET 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.