Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
xml string to xml parser : html chars code are converted

I have an issue with special html chars when I parse a string to xml

My database store a xml document as a string

<?xml version="1.0" encoding="utf-8"?>
  <contenu>
    <bloc>
      <myText>
        My text -&lt;br&gt;- rest of the text
      </myText>
    </bloc>
  </contenu>

I get the data in php, and receive the exact string (error_log show the "& lt;" ). But when I try to get a xml object in javascript with this code

xmltext=the data receive from the php
console.log(xmltext); -> console="<?xml version="1.0" encoding="utf-8"?><contenu><bloc><text>My text -& lt;br& gt;- rest of the text</text></bloc>"
let parser = new DOMParser();
let xmlDoc = parser.parseFromString (xmltext, "text/xml");
let bloc=xmlDoc.getElementsByTagName("bloc")[0];
let tnode=bloc.getElementsByTagName("text")[0];
console.log(tnode.textContent); -> console="My text -
- rest of the text"
document.getElementById("editContenuTablebody").innerHTML=tnode.textContent;

In my html page I want to see in the <p id="editContenuTablebody"></p>

My text -<br>- rest of the text

instead of

My text -
- rest of the text

The parseString convert the html specials char. Is there a way to store the exact string in the xml without conversion ?

The issue is in fact more complicated : the parseString convert the lr/cf and the tab to text node. The xml after the parseString

<contenu>
\n\t <- show as a xml text node, The "contenu" node has 3 child text/bloc/text !
<bloc>
\n\t\t <- show as a xml text node, The "bloc" node has 3 child text/bloc/text !
<myText>
\n\t\t\tMy text -&lt;br&gt;- rest of the text\n\t\t\t  <- the text start and end with \n\t\t\t
</myText>
\n\t\t
</bloc>
\n\t
</contenu>

So I need to delete all the \n et \t code before inserting xml string to my database. Not a big deal, except when I want to debug (some xml strings can have hundreds of node).

I don't know if it's the same problem or not.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda