Parsing DOM with Javascript

D

djdave

My problem is that i need an algorithm parse parse HTML.
For an HTML page, my script has to parse all tags to get all forms
values, even if there is frame, iframe, ...
How can i do such a script ?

Thanks
 
P

pipe

My problem is that i need an algorithm parse parse HTML.
For an HTML page, my script has to parse all tags to get all forms
values, even if there is frame, iframe, ...
How can i do such a script ?

gee, i dont know, can you?

iframes may give you problems, since sometimes, you can get the access
denied msg,
other than that, i would use the innerHTML, and then some old fashoned
regexp work,
but there are probably better ways...
 
A

alu

pipe said:
gee, i dont know, can you?


iframes may give you problems, since sometimes, you can get the access
denied msg,
other than that, i would use the innerHTML, and then some old fashoned
regexp work,
but there are probably better ways...


I was hoping someone in-the-know would respond to this request,
as I'm interested in a solution myself.
Your subject line is "parsing the DOM", while your post
implies simply parsing HTML tags.
If that's the case, I've done this before by simply placing each tag into
an array element. This could be easily adapted to include iframes
and frames, the content of which must be within the same domain.
Very crude solution....

// -------------------------------

// array to hold all html tags
arrayOfTags = new Array();
// populate array
function parseHTML(HTMLcontent) {
// split at <
var re = "<"
arrayOfTags = HTMLcontent.split(re)
// restore split separator

for (var i = 1; i < arrayOfTags.length; i++) {
arrayOfTags = "<" + arrayOfTags
}
}

function outPut(n) {
alert(arrayOfTags[n])
}

// -------------------------------------

<div onclick="outPut(1)">click to see array element 1</div>



-alu
 
T

Thomas 'PointedEars' Lahn

djdave said:
My problem is that i need an algorithm parse parse HTML.
For an HTML page, my script has to parse all tags to get all forms
values, even if there is frame, iframe, ...
How can i do such a script ?

Iterate and recurse through the `frames' collection, access the `forms'
collections of the respective `document' properties/objects and access
their `elements' collections. Whatever you consider "form values", you
may want to look for elements with specific `type' property/attribute
values.

However, there is already a bookmarklet for this, though I have not
tested or analyzed if it works with frames:

<http://www.squarefree.com/bookmarklets/forms.html>

implemented in

<http://chrispederick.com/work/webdeveloper/documentation/features/forms/>


HTH

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top