Solved

Reading XML into dataset and keeping line break from XML

Posted on 2007-12-01
4
938 Views
Last Modified: 2012-06-27
I am reading information from a XML file into a Dataset and loading it to a webpage.  I wanted to keep the format from the XML file such as line break (see code example).  I loaded the xml to dataset as ds.ReadXml(filename) and loaded it do a table.  How can i make line break from text in <blog> in XML file appear in webpage??

<Comments>

    <Name>VAldimf</Name>

    <Time>01.12.2007 12:14:43</Time>

    <Title>slasfdj</Title>

    <Blog>valdij

södfj
 
 
 

asdföj

adsfj
 

asdföj

sadf</Blog>

    <ID>4</ID>

  </Comments>
 
 

...

            foreach (DataRow dr in ds.Tables[0].Rows)

            {

                TableRow tr = new TableRow();

                tr.Cells.Add(new TableCell());

...

                tr.Cells[0].Text = "<FONT size = 2 FACE = Verdana color = #8F8672 >" + dr[3].ToString() + "</FONT>";

                this.BlogTable.Rows.Add(tr);

.....

Open in new window

0
Comment
Question by:va80
  • 2
4 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 20387943
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 200 total points
ID: 20387951
Use :
tr.Cells[0].Text = "<FONT size = 2 FACE = Verdana color = #8F8672 >" + dr[3].ToString().Replace("\n","<br>") + "</FONT>";
               
Replace real newlines with the <br> tag.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20387953
http://msdn2.microsoft.com/en-us/library/ms256097.aspx

So, try this: -


Comments>

    <Name>VAldimf</Name>

    <Time>01.12.2007 12:14:43</Time>

    <Title>slasfdj</Title>

    <Blog xml:space="preserve">valdij

södfj

 

 

 

asdföj

adsfj

 

asdföj

sadf</Blog>

    <ID>4</ID>

  </Comments>

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now