Solved

XML data in ASP.NET

Posted on 2004-10-13
7
736 Views
Last Modified: 2013-11-25
Hi

I have to create a FAQ page in ASP.NET
for example

i need to design the below format of header and listitems
where header is text and listeitems are hyperlinks

but i dont want to hard code Header or the listitems text or its Url's
i want all to be writen in XML file such that ASP.NET reads XML file and generates this output
later i can add/remove Header and URL from XML file




New to Programming   (header)
    o How to Start      (listitems)
    o What are the Requirements

Allready a member
    o How to renew my membership
    o What are the payment methods
.....
....
...
   

Please help me how to design the XML file structure and ASP.NET code which reads from it and displays in above format
0
Comment
Question by:DOT_NET
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12304144
0
 

Author Comment

by:DOT_NET
ID: 12304362
can someone give me working sample
0
 
LVL 2

Accepted Solution

by:
diablocute earned 125 total points
ID: 12305204
(1)Hi,there. I'm assuming that your xml file will look similar to below
<FAQ>
    <Header Name="New to programming">
        <listitem Url="/howtostart.aspx" Name="How to start" />
    </Header>
    <Header Name="Aleady a member">
        <listitem Url="/Howtorenew.aspx" Name="How to renew membership"/>
    </Header>
</FAQ>

(2) In serverside
// Create an xml document & Load the XMl from the file
XmlDocument doc = new XmlDocument();                  
doc.Load(filePath); // path of your XML file

// Retrieve all header from the xml.
XmlNodeList headers  = doc.SelectNodes("FAQ/Header");
StringBuilder headerString = new StringBuilder();

// Iterate through all the headers
foreach ( XmlNode headerNode in headers )
{
// Add headername to the string.
headerString.Append("<h2>" ).Append(headerNode.Attributes["Name"].Value ).Append("</h2><ul>");

// Get all listitems in the current header.
XmlNodeList listitems = headerNode.SelectNodes("listitem");

// Loop through all listitems in the current header and add to the string.
foreach ( XmlNode listNode in listitems )
{
   headerString.Append("<LI><a href=").Append(listNode.Attributes ["Url"].Value).Append( ">").Append( listNode.Attributes["Name"].Value).Append("</a>");
}
headerString.Append("</ul>");
// Pass headerString to the page output using Response.Write
// or assigning into a web control (such as label, panel, etc)
============================================
fyi, I prefer to use StringBuilder, but you can always use string. (Be sure to add Using System.Text if you want to use StringBuilder)
hope this is what you're looking for =)


0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 2

Expert Comment

by:diablocute
ID: 12305211
oops, i forgot to add one more  }
after headerString.Append("</ul>");
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12305241
Here's another approach:  With your ASP.NET project open, click the Project menu in VS and select Add New Item.  Select the Dataset icon in the dialog and give the dataset a filename like FAQ.xsd.  You will get a blank yellowish designer.  In this designer, right click and select Add >> New Element.  You will get a box with two columns.  At the top the name will be element1.  Change this to Header.  Then add some columns that would belong to a Header table (if you had one).  The left column of the box is for the column name; the right for the data type.  Do the same thing and create a ListItems element.  Make sure the Header element has a field that will be a unique key to each Header.  Then make sure the ListItems element has a column that will reference the Header's key.  These elements are defined in an xml schema that ADO.NET uses to create an ADO.NET dataset with data tables for each of these elements.

After creating the elements for your Header and ListItems, right click the dataset designer and select Add >> New Relation.  This is where you join the two tables on the Header key.

Once you have done this, you can add this dataset to a page and add rows to the Header and ListItems data tables.  If you want to save this info as xml, you call the dataset's WriteXml() method, passing it a file name to write the xml to.  Conversely, if you want to read that xml back into the dataset, you call ReadXml(), passing it the file name.

John
0
 
LVL 8

Expert Comment

by:razo
ID: 12305520
what u can do is use an xslt file that define the html format of each element
and the use the xml control of the .net to load both the xml file and the xslt trasnformation
0
 

Author Comment

by:DOT_NET
ID: 12310253
Hi  diablocute
i'll try your code
and get back to u
thanks :)
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
asp.net mvc 2 44
Problem to copy file 14 92
disadvantage of code behind appoarch in asp.net 3 50
Some inputfields not clickable on iPad Safari, Ok in other browsers 3 48
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question