XML async entity causes validation problems -- how do I escape it?

267 views Asked by At

I generate static HTML pages and I've found so far that the best way to do this is using XML to Linq, as this makes manipulating the document quite similar to JavaScript/jQuery.

It has worked well so far, except I added an AddThis button to my website and the following line has caused an XmlException:

<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-51f1474f46ee2d87&async=1&domready=1"></script>

The Exception is:

'=' is an unexpected token. The expected token is ';'. Line 69, position 114.

I ran the line on http://www.xmlvalidation.com and got the following result:

110 The reference to entity "async" must end with the ';' delimiter.

I've searched Google for several minutes trying to find information on the "async" entity or how I can get around it, but many documents claim there are only 5 entities in XML, such as this page: http://www.quackit.com/xml/tutorial/xml_entities.cfm

How can I escape this entity?

Bonus question: What is the async entity and why is it hardly documented anywhere online?

1

There are 1 answers

0
mejdev On BEST ANSWER

It turns out the XML parsers search for '&' and assume that any ampersand is the start of an entity. There are two ways of escaping ampersands depending on the context.

One could use the XML entity &amp;

Since this is a URL, one should use %26 for URL encoding

The line, then, is as follows:

<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-51f1474f46ee2d87%26async=1%26domready=1"></script>