Error parsing XML : The reference to entity “version” must end with the ';' delimiter [duplicate]

大憨熊 提交于 2019-12-01 03:30:35

It looks like something is interpreting your document as XML rather than HTML. XML is much stricter than HTML - one of the rules is that ampersands (&) have a special meaning. They mean "here comes an XML entity", which is a special character. For instance, you can type " to insert ", or > to insert > into your document.

In this case, your code is interpreting &version on line 6 as the start of one of these entities. If you update line 6 as follows:

js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0";

Then you should find that error disappears.

Just had this issue myself. The answer above did not fix the problem. The Facebook buttons do not load. Below is the fix I implemented to resolve both the 500 error presented on the server and then allow for proper loading of the Buttons.

The problem is that if you are using something like Thymeleaf which uses XML. The HTML added to a page must be properly formed. The & will cause the page load to fail with a 500 error if the current version is used within a page.

Current method of including the Javascript SDK for a button. Follow Us, Like etc...

    <div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

Enhancement needed to work with the more strict XML checking. This enhancement will allow for the proper escaping of the XML data and commenting the CDATA works for older browsers.

<div id="fb-root"></div>
<script>
/* <![CDATA[ */
    (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
/* ]]> */
</script>

Did you place the code right under the tag? Because thats where it needs to be placed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!