![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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? |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Binding inside binding question | Yoavo | Avalon | 0 | 12-03-2007 08:24 AM |
| Binding Question (Binding in General) | Jason | Avalon | 2 | 05-09-2007 04:41 AM |
| Calling an XPath on a Binding with an XmlNode causes StackOverflowException | Keith Patrick | Avalon | 0 | 01-05-2007 10:22 AM |
| Xml Binding - Why does XPath return nothing? | jmagaram | Avalon | 0 | 10-13-2006 04:24 PM |
| Binding, XPath & Namespaces | Doug | Avalon | 4 | 01-10-2006 03:52 PM |