#165 ✓invalid
mr_crick

Fix for Content-Type: "text/xml"

Reported by mr_crick | June 13th, 2008 @ 01:58 PM

Prototype does not work correctly, when the documents content type is set to "text/xml". Reason for the failure is the lack of document.body

If wanted, I'll provide a patch to work around this problem by adding a method to document, i.e.

Object.extend( document {
  getBody : function () {
    Try.these( function () { 
        return document.body },
      function () {
        document.body = document.documentElement.getElementsByTagName('body')[0]
        return document.body
      }
  }
} )

and changing all occurences of document.body to document.getBody()

Tested in Firefox 3 and Safari 3

Comments and changes to this ticket

  • Juriy Zaytsev

    Juriy Zaytsev June 13th, 2008 @ 10:56 PM

    mr_crick,

    I don't really see a reason to use Try.these. Also, why change all occurences of document.body to document.getBody() (as you have suggested) if document.body is being defined to point to a proper node in a second try.

    Why not something like:

    document.getBody = function(element) {
      var doc = element ? element.ownerDocument : document;
      return doc.body 
        || doc.documentElement.getElementsByTagName('body')[0] 
        || null;
    }
    
  • John-David Dalton

    John-David Dalton June 13th, 2008 @ 11:17 PM

    IE has issues extending XML nodes in IE, sometimes they just error out.

    Is this what you are tyring to do?

    Patches and unit tests are always welcome though :).

  • mr_crick

    mr_crick June 14th, 2008 @ 09:20 AM

    Juriy Zaytsev: I first tried a solution without getBody by just assigning the value to the body node on script load time. This did not work, because at script load time, the body node does not exist yet. That's why I wanted to postpone the time of assignment. What would be possible, would be the use of of a 'dom:loaded' listener that performs the assignment.

    John-David Dalton: Yes, I was trying to get prototype running on XML documents. After submitting the ticket I realised, that in FF and Safari, some of the nodes are also not extended. So I guess there is no need to fix the document.body issue before XML nodes can be extended. Does anyone know why this is the case? I'll invest some more time into this and submit a patch, if one can fix it at all.

    Cheers

    Marco

  • John-David Dalton

    John-David Dalton June 15th, 2008 @ 05:09 PM

    • State changed from “new” to “invalid”

    Prototype 1.6.0.3 has disabled the ability to extend XML nodes because of this issue.

    The problem should be resolved if/when Prototype moves away from extending nodes and moves toward using wrapper classes.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Pages