?
Solved

Reading XML into dataset and keeping line break from XML

Posted on 2007-12-01
4
Medium Priority
?
954 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
3 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 20387943
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 600 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

864 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