Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why are double semicolons required when using character entities?

Status
Not open for further replies.
Dec 8, 2003
17,047
GB

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 &amp; 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
 
I don't know why the double-semicolons are working for you -- sounds like a bug, honestly.

You said your file contains: [ignore]&nbsp;[/ignore], this is not one of the predefined XML entities, and it's probably confusing the parser. Try changing your .xml file so that it looks like: [ignore]&amp;nbsp;[/ignore].

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 

It is not an XML file - it is an HTML file, as you can see from the code above.

I used "&nbsp;" in my description, but used "&amp;" in the code - but it really could be any HTML character entity. try the code and you'll see what I mean.

Dan
 
nope, &nbsp; fails because it is a not a valid escape set for XML. &amp; doesn't fail because it is valid, so &amp;nbsp; will pass.

I just tried it using xmp tags and it worked fine (except for the nbsp).

Although i figured I should tell you that that method of loading the XML documnet isn't supported in Mozilla :)

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Help, the rampaging, spear-waving, rabid network gnomes are after me!
 
BillyRayPreachersSon -

Only the variantion of HTML called XHTML can be loaded into a DOM -- ordinary HTML cannot because of tags like <br> -- this is not valid XML. However, if it were coded like <br/>, then it would be able to.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Granted.

But for the general case of loading HTML, that's a common problem. Often posters here will not include the entire part of their code that is causing problems, so that's why I mentioned it.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I think the problem is that you use <object> tag to hold the xml data. Try use XML island to hold the XML data as follows, and it should work.

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();">
</body>
</html>

<xml id="myData">
    <myCustomTagSet>
        <customTag>A &amp; B</customTag>
    </myCustomTagSet>
</xml>
 

Unfortunately, we need to use the object syntax, as it is a component that is placed on a page (the code above is a simplified version with enough detail to show the problem at hand).

Thanks for the suggestions though - I think we'll just end up putting ;; at the end of our codes, as it works just fine when we do that.

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top