I'm making a bookmarklet for a website that will need to parse multiple pages. I tried DOMParser
, but it gives an error with the xml option and returns null with html. I tried jQuery, but I'm sure that's using DOMParser somewhere along the way. It does work correctly with PHP, but I'd rather not have to make twice as many requests to webpages.
I'm looking for a standalone javascript plugin to parse xml or html.
Thanks!
Can you not just "parse" the HTML by using the DOM?
If you need to do multiple pages from the same current page, load the other pages in an iFrame and them access the DOM like document.frame[0].contentWindow.document
EDIT: If you wish to avoid loading the external files in other pages, and also executing their script, then use Ajax (XMLHttpRequest) to get the each page. For each page use code like var newdiv = document.createElement('script'); newdiv.innerHTML = ajaxcontent;
and then use the DOM to read content from newdiv. If you don't append the newdiv to the page, this should be just as lightweight as using DOMParser.