The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 16, 2019, 09:49:29 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: "var_dump" a DOM object?  (Read 4584 times)
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« on: November 13, 2007, 03:53:30 PM »

I'm a total JS noob, but would like to echo out a DOM object to attempt to find out why i'm unable to walk it, is this possible? Sounds like it should be, but google has yet to provide me with an answer  Need Help

Cheers,

DM
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: November 13, 2007, 06:03:42 PM »

I have not seen one either - it can be done, of course, but it'd be something to see. Even looking at the DOM in an inspector is kind of weird... I don't like it. I actually prefer to look at HTML and then "see it" in my head.

Are you pretty familiar with the DOM-walking functions? It might be better to talk about your intentions and how to walk/talk the DOM. I'm reasonably good and can probably help.

/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #2 on: November 14, 2007, 02:53:02 AM »

I'm completely new to javascript, and am only fumbling with it now as I simply want to pull data from an XML file to display in Google applet thing - straightforward stuff I thought considering JS is renown for its DOM handling.

I've successfully pulled in my XML file as a DOM object, I just don't know what to do with it from here  Roll Eyes - I've attempted DOM walking 'things' to put content into variables, but I've not got it to work, hence I thought i'd try to view the structure of what I was trying to walk.

XML doc format is:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<get_stats generator="zend" version="1.0">
<url_id>1</url_id><url>http://www.yahoo.com</url>
<total_visits>2</total_visits>
<last_visit>2007-09-17 17:42:54</last_visit>
<status>Success</status>
</get_stats>

That is litterally it. Only one item returned, no duplication of any node.

Any suggestions appreciated Smiley

Cheers,

DM
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: November 14, 2007, 10:06:49 AM »

Hey DM - I thought you were walking HTML rather than XML - so I am less experienced, but the dom funcs are the same in any case.

without id="aname" in the node, you'll not be able to getElementById obviously, so you'll need to either step into children and ask for their nodeName or look for nodes of a particular name from the root. For example, assuming that the variable with a handle to the DOM document is named "theDoc" you could ask this:

lv = theDoc.getElementsByTagName('last_visit');

lv would then be an array of elements under the root named last_visit - so in this case, lv[0] is the item you'd be looking for. I am at a client's, so I don't have my DOM reference handy, but there is a way to ask for all the children of the current node, and then ask each for their node name - so again, if theDoc is the root handle:

alert(theDoc.nodeName) would show an alert window with "get_stats"

I believe I posted a simple XML handler in the Javascript code repository - I wrote it specifically because I didn't want to have to pull the trigger on the dom for simple parsing of a little XML chunk. I'll take a look and post back here.
/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!