Sign in to follow this  
tychon

[web] Firefox and XPCOM

Recommended Posts

tychon    652
Sorry if this is the wrong forum, it just seemed the most appropriate. I'm tinkering with extensions in Firefox and have hit a bit of a stumbling block. What I'm trying to do right now is grab a page's DOM and then use that to add snippets of info on another page. As an example, say I'm viewing the thread list here and I wanted to put a list of the last five posters in the thread entries, instead of just the one. Things of that nature. The problem? The site I'm working with isn't XML well-formed. It's not even HTML well-formed. style elements outside the root element, forms spanning tables, et cetra. I don't run the site so there's no chance of changing this. Since it's not well-formed for XML, I can't use XmlHttpRequest(). Yes, I've looked for ways to parse flat text into an HTML DOM, but it seems either hidden or impossible to do. Plenty on parsing text into an XML DOM, though. Right now I'm tinkering with using the hidden iframe trick, but that seems to have issues in the manner I'm using it. It seems to always have an empty DOM document for it if it's created by an extension. Sooo, I've been flipping through the XPCOM reference on XUL Planet, and it certainly seems like XPCOM might offer a solution, but frankly, I'm lost. Does anyone have familiarity with XPCOM or experiences in a similar issue? Much thanks.

Share this post


Link to post
Share on other sites
markr    1692
You can still fetch a badly formed XML document using XMLHttpRequest. Just don't try to use the responseXML property of it which triggers an attempt to parse it as XML.

As far as I'm aware, you should be able to instantiate the "tagsoup" parser from javascript with XPCOM. Whether you can do this unprivileged, I don't know.

Loading it as an iframe will have all sorts of side effects which you may not want.

---

I believe that the way to create a new DOM document is to use implementation.createDocument() - but that may not be able to do the parsing for you, just create a brand-new document.

Also have a look at the DOMParser object which is definitely available to unprivileged JS.

Mark

Share this post


Link to post
Share on other sites
tychon    652
Unfortunately DOMParser only works with XML/XHTML.

Quote:
contentType: The content type of the string - either text/xml, application/xml, or application/xhtml+xml. Must not be NULL.


I've fiddled with createDocument but I've only been able to get it to return an XmlDocument. Which would work just fine of course if I could find something that'll parse tagsoup HTML.

Of course I might just be doing it wrong, but so far neither of those work. And I've avoided responseText on XmlHttpRequest until I can find a parser for it. It has to be in there somewhere, I just haven't found it yet.

Share this post


Link to post
Share on other sites
tychon    652
Hmm, I may have figured something out -- which was indeed detailed on the DOMParser page, albeit having nothing to do with DOMParser itself. Much obliged to your making me look a bit beyond my nose, hah.

responseText and createContextualFragment seems to be a viable route.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this