Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
parse a html document help please
Old 03-20-2009, 07:13 AM parse a html document help please
Novice Talker

Posts: 9
Trades: 0
hi,

Im writing a sidebar gadget which needs to display the data from the tables in a html page , im using xmlhttprequest() and displaying the request using
document.getElementById('show').innerHTML=xmlhttp. responseText;
this does diplay the page but i only need to display some of the <TD.. elements on the page, could anyone provide me with a good link or explain the process of parsing the html...? I have been searching google and reading w3schools website fot the last 3 days now, I want to keep what little hair i have left now... LOL.

I am only learning javascript so please keep it simple or well commented...
Can post source if this helps?
Thanks in advance, Phill.
phill is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-20-2009, 07:47 AM Re: parse a html document help please
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Depends on HOW you can identify the required elements.

to get all TDs would be:
Code:
var XMLDoc = xmlhttp.responseText;
var m_aeTD = XMLdoc.getElementsByTagName("td");
Then run through the array of TD elements as you would with any array.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-20-2009, 09:27 AM Re: parse a html document help please
Novice Talker

Posts: 9
Trades: 0
Hi chris thank you for the quick reply!

All the elements i want are capital TD's,
eg. <tr><TDclass="col1">textThatIwant</td>

the code below doesnt seem to work for me.. but am i thinking along the right track??

var XMLDoc = xmlhttp.responseText;
var m_aeTD = XMLdoc.getElementsByTagName("TD");
var retrn;
for(x=0;x<m_aeTD.length;x++)
{
retrn = retrn + m_aeTD.item(x).firstChild.nodeValue;
}

//xmlhttp.responseText
document.getElementById('show').innerHTML=retrn;
phill is offline
Reply With Quote
View Public Profile
 
Old 03-20-2009, 09:42 AM Re: parse a html document help please
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
<TDclass

should be

<TD class

note the space
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 03-20-2009, 10:04 AM Re: parse a html document help please
Novice Talker

Posts: 9
Trades: 0
yes its actualy <TD class in the html document ... just a typo in my post...
phill is offline
Reply With Quote
View Public Profile
 
Old 03-20-2009, 10:19 AM Re: parse a html document help please
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Tag names in HTML are case-insensitive. So getElementsByTagName("TD") is the same as getElementsByTagName("td") no matter how it is in your document. I always use lower case.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 03-20-2009, 02:33 PM Re: parse a html document help please
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
the code below doesnt seem to work for me.. but am i thinking along the right track?
What is it doing? or not?

Code:
var retrn = "";
for(x=0;x<m_aeTD.length;x++) {
   retrn += m_aeTD[x].innerHTML;
}
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-20-2009, 06:33 PM Re: parse a html document help please
Novice Talker

Posts: 9
Trades: 0
Sorry I just dont see the fault...
where did i go wrong? this im sure is not rocket science but i just dont see it...
phill is offline
Reply With Quote
View Public Profile
 
Old 03-20-2009, 08:20 PM Re: parse a html document help please
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
retrn = retrn + m_aeTD.item(x).firstChild.nodeValue

javascript arrays/collections are referenced using a C style syntax eg: array[index]

the array.item(index) syntax is Pascal\Delphi\VB\VBScript style

And I shortened the concatenation a little
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-21-2009, 01:58 PM Re: parse a html document help please
Novice Talker

Posts: 9
Trades: 0
I have been somewhat successfull lastnight ...
I was not able to use this

var m_aeTD = XMLdoc.getElementsByTagName("TD");
allways gave me an error...

Instead I have taken the html page source and saved it to my desktop as test.html
and used document.getElementsByTagName() then a for loop which im not quite sure runs right... (but it works...) to display ( document.write) the required <TD tags in a table which "should" add more rows to the table when more devices are on my lan.

im try'n to learn not get somebody to do it for me... but can any of you guys take a look at my code and give me some advice on how to use xmlhttp.resposeText in the same way i have done it in test.html....??

link -http://rapidshare.com/files/211870915/eirstat.gadget.rar.html
MD5: C48CE955E5C53147D4609A3ADA035951
phill is offline
Reply With Quote
View Public Profile
 
Old 03-21-2009, 07:26 PM Re: parse a html document help please
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
var m_aeTD = XMLdoc.getElementsByTagName("TD");
What's the error you get?

you may need to use XMLDoc.document.getElementsByTagName("TD");
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-21-2009, 08:17 PM Re: parse a html document help please
Novice Talker

Posts: 9
Trades: 0
Code:
     var XMLDoc = xmlhttp.responseText;
     alert("test if ok here "+XMLDoc) //works, shows entire page
     var m_aeTD = XMLDoc.getElementsByTagName("TD"); //Fails here!
     alert("test2 "); // no alert....
     alert("m_aeTD = "+m_aeTD);
     alert("m_aeTD = "+m_aeTD[19]);
phill is offline
Reply With Quote
View Public Profile
 
Old 03-22-2009, 02:46 AM Re: parse a html document help please
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
need the error message that you get, or a URI to the page.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-22-2009, 04:05 AM Re: parse a html document help please
Novice Talker

Posts: 9
Trades: 0
using try + catch(err) the error just says "[object Error]" Is that what you meen?
phill is offline
Reply With Quote
View Public Profile
 
Old 03-22-2009, 04:46 AM Re: parse a html document help please
Novice Talker

Posts: 9
Trades: 0
script debugger stops at line 63: var m_aeTD = XMLDoc.getElementsByTagName("TD"); //Fails here!


Object doesn't support this property or method
phill is offline
Reply With Quote
View Public Profile
 
Old 03-22-2009, 06:05 PM Re: parse a html document help please
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Use response.XML in place of response.Text so the document is returned as a XML structured document rather than plain text
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-22-2009, 09:59 PM Re: parse a html document help please
Novice Talker

Posts: 9
Trades: 0
responseXML returns null...
Im doing a lot of reading up on the subject, will let you know if i get the answer thank you for your time,

phill.
phill is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to parse a html document help please
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.56907 seconds with 12 queries