473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

turn lump of text into a parseable document

In my first experimentation with js, I'm writing a greasemonkey script
which adds links to a page which, when clicked, will replace their
parent element with the contents of an element from another URL.

in the following function, pageHTML contains the entire text of an HTML
page, pulled in via GM_xmlhttprequest. The page contains a ul with
id="commentlisting". What I want to do, but can't seem to do, is turn
that lump of html in the pageHTML variable into a document that I can
run document.evaluate and document.getElementById on, just like I can
on the original page.

The second catch below alerts me with "TypeError:
tempnode.getElementById is not a function"
function getExpandedHTML(oldid, pageHTML)
{
GM_log("getExpanded started");
var tempNode;
try {
tempnode = document.createElement("document");
tempnode.innerHTML = pageHTML;
}
catch (e)
{
alert(e);
}
var listnode;
try {
listnode = tempnode.getElementById("commentlisting");
} catch (e)
{
alert(e);
}
//var innerlinks = listnode.evaluate("//a[@href]", listnode,
null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
//addlinkevenets(oldid, innerlinks);

GM_log("getExpanded finished");
return listnode.innerHTML;
}

Sep 24 '05 #1
1 1592


ja************@gmail.com wrote:

The second catch below alerts me with "TypeError:
tempnode.getElementById is not a function"
function getExpandedHTML(oldid, pageHTML)
{
GM_log("getExpanded started");
var tempNode;
try {
tempnode = document.createElement("document");
tempnode.innerHTML = pageHTML;
You are creating an _element_ node and set its innerHTML, you are not
creating a _document_ node. Thus that
listnode = tempnode.getElementById("commentlisting");


fails as only document nodes implement the method getElementById.

As far as I know currently browsers like Mozilla or Opera do not provide
an API to script to parse some string with HTML markup into an HTML
document so you might need to help yourself with creating an iframe and
writing the markup in there. But that will then for instance load images
or other stuff in the HTML so it is not an in memory operation.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 24 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Thomas W | last post by:
I'm developing a web-application where the user sometimes has to enter dates in plain text, allthough a format may be provided to give clues. On the server side this piece of text has to be parsed...
13
by: Csaba Gabor | last post by:
I'm not talking javascript hara-kiri here. I've got a database of web pages or snippets I've created and I'd like to display them in a table. So on my server (in PHP) I take all the files, and...
8
by: Michael Hill | last post by:
I have this input element: <input type='text' name='street' maxlength='20' size='20'> that I only want the user to be able to input to based on a item from a select list: <select...
6
by: ok | last post by:
I tried escape, but it is only good for the special ones like : / ' space etc. I want to turn every charactor into %xx then document.write them. I wonder if i can double % them so I can turn @...
63
by: John Salerno | last post by:
I know there's a request for a good IDE at least once a week on the ng, but hopefully this question is a little different. I'm looking for suggestions for a good cross-platform text editor (which...
1
by: Jay Why | last post by:
I'm working on some drag-n-drop javascript code for a web app, where the company requires all the users to be on Win XP, using IE 6 (so I don't care about cross-browser compatibility - lucky me!) ...
0
by: najmi | last post by:
i don`t know whether this is the best places to share with you all.i have one important document that was saved using microsoft word..when i try to open it, it text turn to...
2
by: javamama | last post by:
Hi, I programmed a web page where two parallel maps can be explored with moving the cursor on the summer and winter buttons. The active button should turn red but now the right hand buttons turn...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.