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 -<br>- 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 -<br>- 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.