Golan_trevize
Golan_trevize

Reputation: 2433

Maintain newlines when parsing text from XML to HTML via JS

so as the tittle pretty much says, I am trying to display some text in an html as it appears in the XML, but the newlines dissapear. This is my code:

var descripcion = document.getElementById("description");
 descripcion.innerHTML = fichas[i].getElementsByTagName("descripcion")[0].childNodes[0].nodeValue;

XML:

...
<descripcion>Descubre los secretos de la elaboración del txakoli, visitando nuestros viñedos y nuestra bodega familiar “Magalarte Lezama” fundada en el siglo XIX; posiblemente una de las pocas bodegas que se mantiene desde entonces.

Tras cuatro generaciones heredando, guardando y mejorando pequeños secretos, apostamos hoy en día por la innovación y el desarrollo, logrando un producto de calidad actual, manteniendo el espíritu del pasado.

</descripcion>

As I said,when I display that text in html, the newline disappears, I tried adding
inside the xml but doesn't work, it behaves like another xml tag.Any solution? thanks!

Upvotes: 0

Views: 59

Answers (1)

Mithfindel
Mithfindel

Reputation: 4706

You will probably want to use the CSS white-space property on the element with id description:

<div id="description" style="white-space: pre-wrap">
</div>

This should retain whitespace and new lines, but still wrap long lines.

Upvotes: 1

Related Questions