Blogidate XML well-formedness

In a comment on my previous blog post, Simon Willison writes: "I'm not too keen on popping up a new window with an external validation service. How about an alternative bookmarklet that just validates XML well-formedness (essential for those of us who use XHTML)?"

Try the new blogidate well-formedness bookmarklet. If this bookmarklet finds an error, it turns the textarea red, selects the part of the textarea where the error is, and puts the error message in the status bar (not in a dialog). If it doesn't find an error, it turns the textarea green.

Update Jan 21, 2005: added a normalize() call so the bookmarklet won't fail when the XML is more than a few kilobytes.

Update Sept 2, 2005: the Valid XHTML user script, which is based on this bookmarklet, is even more cool.

7 Responses to “Blogidate XML well-formedness”

  1. Martijn Says:

    Great bookmarklet, I was thinking of that (validating with the Mozilla parsing machine) regarding your previous post.
    I think, like Simon said, that you could use the DOMParser object also for validating, because I think if the DOMParser can’t parse the content, it displays the error document. I’m not sure though, and with the iframe method it works just as nicely :)

  2. Sam Says:

    Wow, very cool! It doesn’t seem to like non-breaking space elements ( ) though.

  3. Martijn Says:

    This makes it also possible to automatically correct bad html, by using for the created iframe data:text/html and copying the content of the textarea to the iframe and then copy it back. Mozilla automatically corrects the tag soup.
    It’s not xhtml though.

    By the way, I tried to access the frame with the window.frames collection, but there I got a permission denied, which was logical I thought, because It’s a different URL (e.g. data:). But then I saw that you could access the iframe with contentdocument which is way better anyhow.
    But why the difference?

  4. Branchleft Says:

    Validating Your Posts

    I mentioned briefly the importance of checking your blog post syntax for correct validation. Thanks to Jessie Ruderman, your post validation is now just a simple bookmarklet click away. Jessie has written a bookmarklet that allows you to check your…

  5. Roland Tanglao's Weblog Says:

    Jesse Ruderman: Blogidate XML well-formedness

    (SOURCE :”jonu”)- Cool hack! Gotta try this.

  6. atog Says:

    blogidate xml-well-formedness

    a nice bookmarklet wich validates XML well-formedness in textareas. this can come in very handy when you want to validate your posts. <quote>If this bookmarklet finds an error, it turns the textarea red, selects the part of the textarea where…

  7. Windley's Enterprise Computing Weblog Says:

    A Quote Blogmarklet

    Jon Udell, in referencing Jesse Ruderman’s well-formed bookmarklet reminded me that I’ve been meaning to create a small bookmarket of my own.