Re: External node troubles [FF3 RC1]

noon <[email protected]>
Newsgroups gmane.comp.mozilla.devel.dom
Organization http://groups.google.com
Message-ID <[email protected]>
> But it's well-formed enough to be parsed with DOMParser?  Does calling
> overridMimeType("application/xml") on the XMLHttpRequest object before making
> your send() call make this problem go away?

Its well formed enough to be parsed but the responseXML still chokes
with not well-formed errors. responseText works well. Override didn't
help any either.

> > How can I use the DOMParser or the same
> > effect without getting a document object? Or can I strip the rest of
> > the child nodes from this document object?
>
> The latter.  So you can get the doc.documentElement from the DOMParser result
> document, and adopt that element.

The context that I am using this method in is quite dynamic so it
isn't easy to say adopt one element.  I have made some progress
because I can parse and then use functions like getElementsByTagName
against this |doc| node.  But my goal is to be able to use xpath.  And
xpath must have an owner document.  |doc|.innerHTML fails because it
is an XML type and |doc|.BODY doesn't exist.

Since I can't adopt |doc| the next best thing would be to generically
adopt EVERY child node of it and then run my xpath expression against
this collection.  Do you know how I can accomplish this?  (I've tried
using dump object functions that iterate all children but they fail on
this XML document node)

Your help is much appreciated.  I'll repost my code so that you know
what is currently working for me.

get("http://google.com");

function get(url) {
  // XHR code, pass responseText to rs
}

function rs(html) {
	html = html.split(/<body[^>]*>((?:.|\n)*)<\/body>/i)[1];
	var p = new DOMParser();
	var xs = new XMLSerializer();

	$('test').innerHTML = html // xmlserializer needs a dom object

	var doc = p.parseFromString(xs.serializeToString($('test')),"text/
xml");

	alert("Image Count: " + doc.getElementsByTagName('IMG').length); // 1

	// Not sure what to adopt, I need a catch-all. doc.BODY is undefined
}

function $(item) {return document.getElementById(item);}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.