Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    May 2009
    Posts
    813
    Thanks
    123
    Thanked 24 Times in 24 Posts

    Code not XHTML valid js newbie

    I have this code:
    Code:
    <div class="addthis_toolbox addthis_32x32_style addthis_default_style">
    <a class="addthis_button_facebook_follow" addthis:userid=""></a>
    <a class="addthis_button_twitter_follow" addthis:userid="LewishamCT"></a>
    <a class="addthis_button_youtube_follow" addthis:userid="LewishamCT"></a></div>
    <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-"></script>
    The addthis:userid is adding an error to the script. Even though it is an external script, it is not validating as valid XHTML. Can anyone rework the code for me so it validates?
    www.lewishamctscheme.org.uk

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,877
    Thanks
    6
    Thanked 1,035 Times in 1,008 Posts
    Look at http://support.addthis.com/customer/...his-client-api in the section “Valid XHTML”.

  • #3
    Regular Coder
    Join Date
    May 2009
    Posts
    813
    Thanks
    123
    Thanked 24 Times in 24 Posts
    Hi Stephan, thanks for your response,
    Yes I already have this code if you look at the site but am still getting the error. it just does not work with the validation as it declares. With so many of these on the web someone must know how they validate. Not everyone can be hosting their sites.

  • #4
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    Where's your xmlns:addthis attribute?
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #5
    Regular Coder
    Join Date
    May 2009
    Posts
    813
    Thanks
    123
    Thanked 24 Times in 24 Posts
    Sorry I dont know what that is: if you mean the longer DTD statement, it is not needed when you add the inline code.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by quartzy View Post
    Sorry I dont know what that is: if you mean the longer DTD statement, it is not needed when you add the inline code.
    It is if you want it to validate properly.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Regular Coder
    Join Date
    May 2009
    Posts
    813
    Thanks
    123
    Thanked 24 Times in 24 Posts
    OK, I did have it though and it still did not validate, so I removed it.

    I added it back and now I have an 2 errors, possibly more, as it is saying xmlns is not recognised and cannot continue

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es" xmlns:addthis="http://www.addthis.com/help/api-spec"
    [
      <!ATTLIST a addthis:url CDATA #IMPLIED>
      <!ATTLIST a addthis:title CDATA #IMPLIED>
    ]>
    Last edited by quartzy; 07-10-2012 at 11:17 AM.

  • #8
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,372
    Thanks
    32
    Thanked 286 Times in 280 Posts
    Quote Originally Posted by quartzy View Post
    I added it back and now I have an 2 errors, possibly more, as it is saying xmlns is not recognised and cannot continue

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es" xmlns:addthis="http://www.addthis.com/help/api-spec"
    [
      <!ATTLIST a addthis:url CDATA #IMPLIED>
      <!ATTLIST a addthis:title CDATA #IMPLIED>
    ]>
    You may want to brush up on your XML skills considering how basic the above errors are. For some reason, you inserted attributes that should appear as part of the root element start tag into a document type declaration.

    As for your validity issue, first, you start with a basic XHTML document type (DOCTYPE) declaration and root (html) element start tag:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    Then you add an internal subset to the document type declaration with all of the new attributes declared:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
    	<!ATTLIST a addthis:url CDATA #IMPLIED>
    	<!ATTLIST a addthis:title CDATA #IMPLIED>
    	<!ATTLIST a addthis:userid CDATA #IMPLIED>
    ]>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    (The internal subset is everything between the brackets.)

    Then you declare the addthis namespace used by the new attributes on the root element:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
    	<!ATTLIST a addthis:url CDATA #IMPLIED>
    	<!ATTLIST a addthis:title CDATA #IMPLIED>
    	<!ATTLIST a addthis:userid CDATA #IMPLIED>
    ]>
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:addthis="http://www.addthis.com/help/api-spec" xml:lang="en" lang="en">
    Now, you are valid.

    However, you still have an XML error because you're using a non-default (ISO-8859-1) encoding for your document and didn't declare it using an XML declaration; you only declared it via a meta element, which has no effect whatsoever in XML. So then you add the missing XML declaration:

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
    	<!ATTLIST a addthis:url CDATA #IMPLIED>
    	<!ATTLIST a addthis:title CDATA #IMPLIED>
    	<!ATTLIST a addthis:userid CDATA #IMPLIED>
    ]>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:addthis="http://www.addthis.com/help/api-spec">
    Mission accomplished... Except the part where you will now have the characters "]>" at the top of your document when rendered by a browser because you're serving your document as an HTML document (not an XML/XHTML document), and internal subsets are not supported in HTML. And Internet Explorer 6—that dinosaur of a browser which your code indicates you are trying to support—will render your page in quirks mode because you're using an XML declaration that that ancient, 11+-year-old browser cannot handle.

    You could serve your document as an XML/XHTML document, but then you'd have to forget supporting Internet Explorer 8 and older since IE didn't support XHTML before IE9.

    If you're really concerned about both validity and maximum Internet Explorer compatibility, I would consider simply not using the AddThis widget. There are some workarounds, but it's a lot of work for something that probably no one will use in the first place.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • Users who have thanked Arbitrator for this post:

    quartzy (07-13-2012)

  • #9
    Regular Coder
    Join Date
    May 2009
    Posts
    813
    Thanks
    123
    Thanked 24 Times in 24 Posts
    Thank you arbitrator for your detailed responses, the problems are that I need to use the addthis as he likes the share capacity. But as the doc types will throw up errors in certain browsers I cannot use the xml code you suggested. So I have to stay with one error. I will complain to addthis and ask them to work on a valid option. I have changed the charset to utf 8 just for this page and it does pass validation now. So that is the best I can hope for. It is only for a charity anyway.
    Last edited by quartzy; 07-13-2012 at 12:32 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •