Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to tell Firefox NOT to do DOM-Tree creation

1 view
Skip to first unread message

ExtDev

unread,
Dec 14, 2008, 1:32:31 PM12/14/08
to
Hi,

I try to create an extension for Fitrfox that does something with a
requested XML document.
I want to pass the whole content of the document to a function, so I
don't need the DOM tree.

Since I will deal with very large XML documents it would be annoying
if FF would do the DOM tree creation.

How can I tell Firefox within my extension NOT to do the DOM-Tree
creation?

Boris Zbarsky

unread,
Dec 14, 2008, 2:18:19 PM12/14/08
to
ExtDev wrote:
> I try to create an extension for Fitrfox that does something with a
> requested XML document.
> I want to pass the whole content of the document to a function, so I
> don't need the DOM tree.

I must be missing some context here. What are you starting with? A
string? A URI? Something else? What are you doing with it, exactly?
What do you want to get out of your operation?

-Boris

ExtDev

unread,
Dec 14, 2008, 3:24:53 PM12/14/08
to
Hi Boris,
thx for your answer!

My plan is:
Open a XML document with FF (by typing the URL in the adress bar or by
klicking a link etc)
Then my extension passes that document (maybe as a string) to a
function.
That function does some XSL transformation (without using the FF's
internal XSLT processor) and returns the result and that result should
appear in the browser window.

I'm still in the planing phase so I can't describe it much more
exactly.

-Dev

Boris Zbarsky

unread,
Dec 14, 2008, 7:22:10 PM12/14/08
to
ExtDev wrote:
> Open a XML document with FF (by typing the URL in the adress bar or by
> klicking a link etc)
> Then my extension passes that document (maybe as a string) to a
> function.
> That function does some XSL transformation (without using the FF's
> internal XSLT processor) and returns the result and that result should
> appear in the browser window.

That's actually a bit of a pain, because you have to prevent the normal
XML handling (but keep enough of it around that you can show the result
of your XSL transformation, right?

In any case, you can easily get XML documents as strings without parsing
if you're doing XHR or some such, but to get them that way when loading
in the URL bar you'd have to suppress the normal XML handling.

-Boris

ExtDev

unread,
Dec 15, 2008, 3:32:36 PM12/15/08
to
Boris wrote:
> That's actually a bit of a pain, because you have to prevent the normal
> XML handling (but keep enough of it around that you can show the result
> of your XSL transformation, right?

You are right, it sounds painful to me, too.
Preventing the normal XML handling is the point, I think.
(For showing the result of my XSL transformation maybe I can do some
coding/transformation so that I dont need FF's XML handling at that
point.)

> In any case, you can easily get XML documents as strings without parsing
> if you're doing XHR or some such

The XMLHttpRequest object sounds interesting... maybe it fits my needs
in a script together with suppressing the normal XML loading at all.

>, but to get them that way when loading
> in the URL bar you'd have to suppress the normal XML handling.

Do you know how to do that suppressing of normal XML handling?
Or at least suppressing the XSLT handling? (I asked that in the xslt
group, but there is no fast answering boris)
Is it possible via an extension or is more deeper FF hacking
necessary?

-Dev

Boris Zbarsky

unread,
Dec 15, 2008, 4:36:56 PM12/15/08
to
ExtDev wrote:
> You are right, it sounds painful to me, too.
> Preventing the normal XML handling is the point, I think.
> (For showing the result of my XSL transformation maybe I can do some
> coding/transformation so that I dont need FF's XML handling at that
> point.)

You can get there by unregistering the Gecko-Content-Viewers entries
added for text/xml, application/xml, application/rdf+xml, and text/rdf.
See
http://mxr.mozilla.org/mozilla-central/source/layout/build/nsContentDLF.cpp#516
for how it's done at shutdown.

That said, this won't help with application/xhtml+xml, image/svg+xml,
etc. Not sure whether you care.

> The XMLHttpRequest object sounds interesting... maybe it fits my needs
> in a script together with suppressing the normal XML loading at all.

If you do use XHR, you can set the override type to text/plain to
suppress parsing as XML. Then you can get the text as responseText.

> Do you know how to do that suppressing of normal XML handling?

See above. An extension can remove those category entries.

-Boris

ExtDev

unread,
Dec 15, 2008, 5:15:45 PM12/15/08
to
Somehow my last post wasn't successful, so here again in short:

XHR sounds interesting, maybe I can use it somehow in conjunction with
suppressing XML handling.

How can I suppress the normal XML handling?

(maybe showing the XSLT result works without that XML handling
somehow)

Or at least how can I suppress the internal XSL transformation?

-Dev

ExtDev

unread,
Dec 16, 2008, 8:49:33 PM12/16/08
to
Hi Boris, thx for your answer.

On Dec 15, 10:36 pm, Boris Zbarsky <bzbar...@mit.edu> wrote:

> You can get there by unregistering the Gecko-Content-Viewers entries
> added for text/xml, application/xml, application/rdf+xml, and text/rdf.

>   Seehttp://mxr.mozilla.org/mozilla-central/source/layout/build/nsContentD...


> for how it's done at shutdown.

Sounds great.
So after unregistering, the xml documents are loaded but not shown in
the browser or are not loaded at all?
Unfortunately I cant find any example how (and with what parameters)
to call UnregisterTypes() from an extension.

Is there a similar way to suppress only the internal XSLT handling?

> If you do use XHR, you can set the override type to text/plain to
> suppress parsing as XML.  Then you can get the text as responseText.

Ok, with XHR I can send a request and use that plaintext version of
the requested XML document, thats fine.
Now I need the XSL file. Do I have to parse the XML file and find and
follow (request) the link to the XSL file myself or is there a more
simple way to get the XSLT instructions?

But with XMLHttpRequest.responseXML there is a parsed and DOMed
version, too.
So this is not really perfect for performance, right?


Greetings
-Dev

Boris Zbarsky

unread,
Dec 16, 2008, 10:11:36 PM12/16/08
to
ExtDev wrote:
> So after unregistering, the xml documents are loaded but not shown in
> the browser or are not loaded at all?

XHR will load them. Trying to load them in a browser window will put up
a helper app dialog, unless another handler is installed.

> Unfortunately I cant find any example how (and with what parameters)
> to call UnregisterTypes() from an extension.

The code in nsContentDLF is an example, no? It should be pretty
straightforward to translate to JS.

> Is there a similar way to suppress only the internal XSLT handling?

Not that I know of.

> Now I need the XSL file. Do I have to parse the XML file and find and
> follow (request) the link to the XSL file myself or is there a more
> simple way to get the XSLT instructions?

If you want to get at the XSL PI in the XML file, yes... You might be
able to use nsISAXXMLReader to parse without building a DOM. Not sure
whether you could just tell the parser to stop after finding your PI if
you're doing that.

-Boris

0 new messages