Vitalij
Vitalij

Reputation: 4625

Binding to external XML doesn't work, but adding XML using XData makes it work

Here is the code for App.xaml:

<!-- <XmlDataProvider x:Key="BookmarkData" Source="testData.xml" XPath="/Favourites"/>-->

<XmlDataProvider x:Key="BookmarkData" XPath="/Favorites">
    <x:XData>
        <Favorites>
            <Bookmark>
                <Title>Google</Title>
                <URL>http://www.google.com</URL>
            </Bookmark>
            <Bookmark>
                <Title>Amazon</Title>
                <URL>http://www.amazon.com</URL>
            </Bookmark>
            <Bookmark>
                <Title>Slashdot</Title>
                <URL>http://www.slashdot.com</URL>
            </Bookmark>
            <Bookmark>
                <Title>Ars Technica</Title>
                <URL>http://www.arstechnica.com</URL>
            </Bookmark>
            <Bookmark>
                <Title>New Egg</Title>
                <URL>http://www.newegg.com</URL>
            </Bookmark>
        </Favorites>
    </x:XData>
</XmlDataProvider>

Commented out line isn't working. Path is correct.

Here is the XML file:

<Favorites>
        <Bookmark>
                  <Title>Google</Title>
                  <URL>http://www.google.com</URL>
        </Bookmark>
        <Bookmark>
                  <Title>Amazon</Title>
                  <URL>http://www.amazon.com</URL>
        </Bookmark>
        <Bookmark>
                  <Title>Slashdot</Title>
                  <URL>http://www.slashdot.com</URL>
        </Bookmark>
        <Bookmark>
                  <Title>Ars Technica</Title>
                  <URL>http://www.arstechnica.com</URL>
        </Bookmark>
        <Bookmark>
                 <Title>New Egg</Title>
                 <URL>http://www.newegg.com</URL>
        </Bookmark>
</Favorites>

Why binding is happening in one case, but not the other?

Upvotes: 0

Views: 272

Answers (1)

Athari
Athari

Reputation: 34293

The difference is in XPath. Compare

XPath="/Favourites"

with

XPath="/Favorites"

Upvotes: 1

Related Questions