开发者

Line breaks from imported XML

开发者 https://www.devze.com 2023-02-19 07:58 出处:网络
I would like to know how to maintain line breaks in my imported XML document. All loads well but I loose the breaks in each paragraph from the node name \"newsstory\". I originally separated each para

I would like to know how to maintain line breaks in my imported XML document. All loads well but I loose the breaks in each paragraph from the node name "newsstory". I originally separated each paragraph with

in the HTML version. Here's the example code:

$(document).ready(function()
              {
                $.ajax({
                  type: "GET",
           开发者_运维百科       url: "xml/news.xml",
                  dataType: "xml",
                  success: manipulateXml3
                });
              }); 

              function  manipulateXml3(data)
              {
                //find every Tutorial and print the author
                $(data).find("news").each(function()
                {

                  var newsheadline = $(this).find('newsheadline').text();
                  var reporter = $(this).find('reporter').text();
                  var agency = $(this).find('agency').text();
                  var imageurl = $(this).attr('imageurl');
                  var cutline = $(this).find('cutline').text();
                  var newsstory = $(this).find('newsstory').text();    

              html = '<h1>'+newsheadline+'</h1><h2>'+reporter+'</h2><h2>'+agency+'</h2>';
              html +='<div class="news">';
              html +='<img src="' + imageurl + '" title="'+ cutline +'" width="200"/>';
              html += ''+newsstory+''; 
              html += '</div>';

                  $("#tab").append(html);

                });
              }


I think it's because you use .text() wich extracts the text and ignores markup( asuming the linebreaks you refer to are <br />-tags).

use var newsstory = $(this).find('newsstory').html(); instead and it should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消