[Greasemonkey] Re: Greasemoney 0.6.4
Aaron Boodman
zboogs at gmail.com
Sun Dec 4 12:38:41 EST 2005
You really have three choices:
The easiest way is to just use unsafeWindow.DOMParser:
alert(new unsafeWindow.DOMParser().parseFromString("<foo/>", "text/xml"));
Though, as the name says, unsafeWindow isn't as safe as using normal
Greasemonkey APIs. See
http://greasemonkey.mozdev.org/authoring.html#unsafeWindow for more
information on this to decide whether it's appropriate for you.
You can also use a new XML API which just came out in Firefox 1.5
called E4X. I personally prefer it, but it seems to be stricter than
DOMParser, which caused some people some headaches.
It also doesn't like XML declarations (<?xml version="1.0"?>) so if
the thing you're trying to parse has one, you need to use a regex to
remove it before parsing it. eg:
var foo = new XML(strXMLWithDecl.replace(/<\?xml.*?\?>/g, ""));
You can get more information about e4x here:
http://developer.mozilla.org/en/docs/E4X
http://en.wikipedia.org/wiki/E4X
http://www.linkwerk.com/pub/javascript/e4x/e4x-tester/
Finally, if what you're really trying to parse in XHTML which has some
likelihood of being invalid tag soup, you may want to use this hack
that I demonstrated for someone else:
http://youngpup.net/userscripts/htmlparserexample.user.js
- a
On 12/1/05, Andrew Murphy <andrewm1986 at gmail.com> wrote:
> This new version breaks some code where I go
>
> var domparser = new DOMParser();
>
> Saying...
>
> Error: DOMParser is not a constructor
> Source File:
> Line: 233
> Source Code:
> 233.
>
> I am guessing this is to do with the new security stuff, how can I change my
> code to be 0.6.4 compliant?
>
> Andrew
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>
More information about the Greasemonkey
mailing list