开发者

document.evaluate in chrome and firefox

I need help with this. I am new to using XPath in javascript and this one has stumped me.

My script retrieves the contents of a web page using xmlhttp and then wraps it up in a 'div':

            div=document.createElement('div');
            div.innerHTML=xmlhttp.responseText.replace(/<img[^>]*>/); 

I need to access the body content of this wrapped division and I am using Xpath to do this:

bodyContent = document.evaluate("//*[@id='bodyContent']", div ,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
bodyContent = bodyContent.snapshotItem(0);

While this works perfectly well in firefox and retrieves the required XpathObject it does not give the desired result for google chrome browser. Where instead of returning the bodyC开发者_开发技巧ontent division of the 'div' element created (and passed as contextNode) it returns the bodyContent of the current document page.

I have checked and in chrome -- the correct xmlhttp.reponseText is received.

Any ideas regarding this?

Thanks,


Does document.evaluate(".//*[@id='bodyContent']", div ,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null) give you the desired result in both browsers?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜