BillyRayPreachersSon
Programmer
This is driving me crazy... And I can't for the life of me work out why, or find any reference to this issue.
When loading data into an XML DOM, it seems that using character entities causes a problem. For example, " " causes the loadXML() method to fail. However, if I put 2 semicolons at the end: " ;", it works just fine!
I've built a simple test harness to show my problem:
Code:
<html>
<head>
<script type="text/javascript">
<!--
function testXMLLoad() {
var myData = document.getElementById('myData').innerHTML;
var xmlDoc = document.createElement('xml');
if (!xmlDoc.loadXML(myData)) alert('Loading failed!');
}
//-->
</script>
</head>
<body onload="testXMLLoad();">
<object id="myData" data="" type="text/x-scriptlet">
<myCustomTagSet>
<customTag>A & B</customTag>
</myCustomTagSet>
</object>
</body>
</html>
The above code will fail, but if you insert the extra semicolon, it works just fine.
Can anyone explain why this is so?
Thanks!
Dan