XML File
<?xml version="1.0" encoding="utf-8"?>
<Eticket>
<BookingRef>17313</BookingRef>
<CompID>HA</CompID>
<DecimalPreference>2</DecimalPreference>
<AttachGDSRules>False</AttachGDSRules>
<FareDetails>
<BaseFare>1440</BaseFare>
<Fees>0</Fees>
</FareDetails>
<ClientInfo>
<Client>xyz abc</Client>
<Address>70 pqrlane</Address>
</ClientInfo>
</Eticket>
ASPX
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/temp/temp.xml"></asp:XmlDataSource>
<asp:ListView ID="ListView1" runat="server" DataSourceID = "XmlDataSource1">
<LayoutTemplate>
<div id="ItemPlaceholderContainer" runat="server">
<span id="ItemPlaceholder" runat="server"></span>
</div>
</LayoutTemplate>
<ItemTemplate>
<div class="Eticket">
<asp:Label ID="BookingRef" runat="server" datasrc="#text" Text='<%#XPath("BookingRef") %>'></asp:Label>
<asp:Label ID="CompID" runat="server" Text='<%#XPath("CompID") %>'></asp:Label>
<asp:Label ID="DecimalPreference" runat="server" Text='<%#XPath("DecimalPreference") %>'></asp:Label>
<asp:Label ID="BaseFare" runat="server" Text='<%#XPath("BaseFare") %>'></asp:Label>
<asp:Label ID="Client" runat="server" Text='<%#XPath("Client") %>'></asp:Label>
<asp:Label ID="Address" runat="server" Text='<%#XPath("Address") %>'></asp:Label>
</div>
</ItemTemplate>
</asp:ListView>
Above data returns me only child values i.e.
Expected output is:
17313 HA 2 1440 xyz abc 70 pqrlane
Actual output I am getting is:
1440 xyz abc 70 pqrlane
Please let me know where i am going wrong.
Hope this information is enough if any more details needed ask for the same.
Thank you
I can’t test this, but I guess
XmlDataSourceassumes you have a root element, that contains one or more entities. Your XML-file contains only one entity at the root.Either wrap the xml file with another element:
Or specify an XPath-property on the
XmlDataSource: