Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!