[Greasemonkey] Accessing XML document tree using GM_xmlhttpRequest

Anton Berezin tobez at tobez.org
Sun Feb 12 19:41:08 EST 2006


On Sun, Feb 12, 2006 at 09:59:05AM -0800, David A. wrote:

> I'm a relative GM newbie and am trying to find coding
> instructions for accessing the XML document tree
> through GM_xmlhttpRequest. Here's what I want to do:
> 
> After doing a Google search, I want to send the query
> to another search engine. This other search engine
> returns a XHTML doc with the information I need stored
> in elements and attribues that are named "title1,
> title2..." (These names are given to a link <a
> href...> element)
> 
> I then want to extract said attributes/elements and
> use them to construct links in the Google search page.
> 
> I haven't found any clear documentation on accessing
> the DOM of XML documents, however, so I can't get what
> I need. Could anyone point me to instructions or
> provide code samples that might work.

I'd say something like this should help:

    function str2xml(str)
    {
        var parser = new DOMParser();
        return parser.parseFromString(str, "text/xml");
    }

    var mydoc = str2xml(...xml http request result...);

Then access mydoc as you would a normal document
mydoc.getElementsByTagName/mydoc.getElementById etc.

\Anton.
-- 
An undefined problem has an infinite number of solutions.
-- Robert A. Humphrey


More information about the Greasemonkey mailing list