DetailsView with XmlDataSource (perhaps XPath issue?)

P

pompair

Hello,

I'm making a quiz game for fun. I have an xml file like this:

<?xml version="1.0" encoding="utf-8" ?>
<results>
<index>99</index>
<answers>11</answers>
<questions>
<question id="1">
<spindex>1</spindex>
<text>question1</text>
</question>
<question id="2">
<spindex>2</spindex>
<text>question2</text>
</question>
... etc ...
</questions>
</results>


Then I have DetailsView setup like this:

<asp:DetailsView ID="DetailsView1" runat="server"
AllowPaging="True" AutoGenerateRows="False"
DataSourceID="ds1" DataKeyNames="id">
<Fields>
<asp:BoundField DataField="id" HeaderText="id"
SortExpression="id" />
<asp:BoundField DataField="text" HeaderText="text"
SortExpression="text" />
</Fields>
</asp:DetailsView>


I have XmlDataSource setup like this:
<asp:XmlDataSource ID="ds1" runat="server" DataFile="~/
XMLFile1.xml" XPath="//results/questions/question">
</asp:XmlDataSource>



Running the webform causes error: "A field or property with the name
'text' was not found on the selected data source".

The app works if I move the <text> fields from elements to attributes!
Like this:

<?xml version="1.0" encoding="utf-8" ?>
<results>
<index>99</index>
<answers>11</answers>
<questions>
<question id="1" text="q2">
<spindex>1</spindex>
</question>
<question id="2" text="q2">
<spindex>2</spindex>
</question>
... etc....
</questions>
</results>

So I guess it's a XPath problem in my XmlDataSource's XPath setting.
How to make this work with the original xml file (with the <text>
fields as elementst)??

-pom-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top