By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Parsing DOM with Javascript

P: n/a
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

Oct 14 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
>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?
Thanks


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...

Oct 14 '05 #2

P: n/a
alu

"pipe" <au********@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
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?
Thanks


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[i] = "<" + arrayOfTags[i]
}
}

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

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

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

-alu
Oct 15 '05 #3

P: n/a
djdave wrote:
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
Oct 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.