![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Xml Binding - Why does XPath return nothing? I am trying to bind to an XmlElement but it isn't working. Why isn't the third binding returning any text? These are my Xaml fragments: <TextBlock Text="{Binding Path=OuterXml}"></TextBlock> <TextBlock Text="{Binding XPath=*}"></TextBlock> <TextBlock Text="{Binding XPath=FirstName}"></TextBlock> This is the text returned from the first binding: <Person xmlns="jdata"> <PersonID>4</PersonID> <FirstName>Justin</FirstName> <LastName>Magaram</LastName> </Person> The second binding returns '4' which I think is correct. But the third binding returns nothing. I've tried different flavors: ../FirstName jdata:FirstName The XmlDataProvider is created in code. There is no reference to the XmlDataProvider in the markup. The Xml looks like this: <Sample xmlns="jdata"> <Person>... <Person>... I load it into a DataSet: sampleDataSet.ReadXml(@"Sample.xml"); I then create an XmlDataDocument: xmlDoc = new XmlDataDocument(sampleDataSet); To do any XPath against xmlDoc, it seems I need to create a namespace manager: namespaceMgr = new XmlNamespaceManager(xmlDoc.NameTable); namespaceMgr.AddNamespace("default", sampleDataSet.Namespace); I then create my XmlDataProvider: XmlDataProvider xp = new XmlDataProvider(); xp.Document = f.XmlDoc; xp.XmlNamespaceManager = f.NamespaceManager; xp.XPath = "/"; Any here I assign my listbox to the data: XmlNodeList nodeList = xp.Document.SelectNodes(@"/default:Sample/default:Person",namespaceMgr); listbox1.DataContext = xp; listbox1.ItemsSource = nodeList; By the way, it is really annoying to have to preface all elements in the XPath with 'default:'. Is there any way to avoid this? |
My System Specs![]() |