Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Xml Binding - Why does XPath return nothing?

Closed Thread
 
Thread Tools Display Modes
Old 10-13-2006   #1 (permalink)
jmagaram
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?
Closed Thread

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








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

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 42 43 44 45 46 47 48 49 50