Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda