I'm parsing an XML file and having issues that seem to have to do with carriage returns (or maybe line feeds) and tabs (or white space) in the XML file. They trip up my JavaScript and return nothing instead of the data.
Here's a snippet of the JS code:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
fullXMLContent = xhttp.responseXML;
}
};
xhttp.open("GET", xmlPathname, true);
xhttp.send();
var navLocationMain = fullXMLContent.getElementsByTagName("locationMainTitle");
projectLocationMain = navLocationMain[0].childNodes[0].data;
document.getElementById("Nav_Top_Left-courseLocationMain").innerHTML = projectLocationMain;
This XML works and returns "INTRODUCTION":
<locationMainTitle><![CDATA[<div style="margin-top: 12px">INTRODUCTION </div>]]></locationMainTitle>
This XML doesn't work and returns nothing:
<locationMainTitle>
<![CDATA[<div style="margin-top: 12px">INTRODUCTION </div>]]>
</locationMainTitle>
The only difference is the carriage returns and tabs in the second example. This happens in all browsers I've tested so far.
I'm trying to preserve the readability and easier editing of the formatting that includes carriage returns and tabs in the XML file.
I saw one reference that mentioned a CR, LF, tab or white space can cause problems in parsing XML but I don't know how to get around that with my JS an still preserve the formatting in the XML file.