[Greasemonkey] Accessing XML document tree using GM_xmlhttpRequest
Mitchell Mebane
mitchell.mebane at gmail.com
Mon Feb 13 15:53:56 EST 2006
Anton Berezin wrote:
> 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.
>
Is there a way to do this for HTML that isn't perfectly valid?
--Mitchell Mebane
More information about the Greasemonkey
mailing list