Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 24, 2010 04:52 AM by Ahmed Moosa
Member
30 Points
71 Posts
Oct 24, 2010 02:21 AM|LINK
Greeting, What is the best practice to read all attributes from a child elements by ID attributes using C# in xml file listed down. Thank you, <?xml version="1.0" encoding="utf-8"?> <WinDLN> <Program ID="1" Name="CIS562" StartDate="9/8/2010 5:50:00 PM" EndDate="9/8/2010 9:15:00 PM" /> <Program ID="2" Name="CIS532" StartDate="10/8/2010 5:50:00 PM" EndDate="10/8/2010 9:15:00 PM" /> <Program ID="3" Name="ECE552" StartDate="6/8/2010 5:50:00 PM" EndDate="6/8/2010 9:15:00 PM" /> </WinDLN>
Star
7784 Points
1232 Posts
Oct 24, 2010 04:52 AM|LINK
hi
i think it "Xpath" .
look at this example : i am using GridView, XmlDataSource and Filtering it using Dropdownlist
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="XmlDataSource1" > <Columns> <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" /> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="StartDate" HeaderText="StartDate" SortExpression="StartDate" /> <asp:BoundField DataField="EndDate" HeaderText="EndDate" SortExpression="EndDate" /> </Columns> </asp:GridView> <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml" > </asp:XmlDataSource> <br /> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> </asp:DropDownList>
and when user select an and id number from the dropdownlist menu put this code:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { XmlDataSource1.XPath = string.Format("/WinDLN/Program[@ID='{0}']", DropDownList1.SelectedValue); }
hope this helps
Ahmed
Eyla
Member
30 Points
71 Posts
Read child elements using C# from xml
Oct 24, 2010 02:21 AM|LINK
Greeting,
What is the best practice to read all attributes from a child elements by ID attributes using C# in xml file listed down.
Thank you,
<?xml version="1.0" encoding="utf-8"?>
<WinDLN>
<Program ID="1" Name="CIS562" StartDate="9/8/2010 5:50:00 PM" EndDate="9/8/2010 9:15:00 PM" />
<Program ID="2" Name="CIS532" StartDate="10/8/2010 5:50:00 PM" EndDate="10/8/2010 9:15:00 PM" />
<Program ID="3" Name="ECE552" StartDate="6/8/2010 5:50:00 PM" EndDate="6/8/2010 9:15:00 PM" />
</WinDLN>
Ahmed Moosa
Star
7784 Points
1232 Posts
Re: Read child elements using C# from xml
Oct 24, 2010 04:52 AM|LINK
hi
i think it "Xpath" .
look at this example : i am using GridView, XmlDataSource and Filtering it using Dropdownlist
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="XmlDataSource1" > <Columns> <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" /> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="StartDate" HeaderText="StartDate" SortExpression="StartDate" /> <asp:BoundField DataField="EndDate" HeaderText="EndDate" SortExpression="EndDate" /> </Columns> </asp:GridView> <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml" > </asp:XmlDataSource> <br /> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> </asp:DropDownList>and when user select an and id number from the dropdownlist menu put this code:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { XmlDataSource1.XPath = string.Format("/WinDLN/Program[@ID='{0}']", DropDownList1.SelectedValue); }hope this helps
Ahmed
MCC - MCPD -MCTS