/    Sign up×
Community /Pin to ProfileBookmark

Capturing XML data using <span>

A question on why i am not able to access my XML document.
The first bit of code below is my attempt to grab the data out of the XML document ticker_trial3.xml. It errors out when i run the window saying that passedNode.childNodes is null or does not exist. But i don’t understand since it calls the correct parent ticker but why can it not see the childs?

I ultimately would like to pull the groups of childNodes out separately and then put them on separate rows within a small table. Any help would be apreciated.

–document1.htm–
<html>
<head>
var xmlDoc = new ActiveXObject(“microsoft.xmldom”);
xmlDoc.async=false;
xmlDoc.load(“../ticker_trial3.xml”);
ticker=xmlDoc.documentElement;
newHTML=””;

function start()
{
newHTML+=(“<table border>”);
newHTML+=(“<caption>”);
newHTML+=(“Employee Directory”);
newHTML+=(“</caption>”);
buildTree(“ticker”);
newHTML+=(“</table>”);
document.all.news_ticker.innerHTML=newHTML;
}

function buildTree(passedNode) {
var children = passedNode.childNodes.length;
for (var j=0; j<children; j++) {
Node=passedNode.childNodes.item(j)
if (!Node.hasChildNodes()) {
if (Node.parentNode.nodeName==”date”) {
newHTML+=(“<tr><td>” + Node.text + “</td>”);
}
if (Node.parentNode.nodeName==”name”) {
newHTML+=(“<td>” + Node.text + “</td></tr>”);
}
}
buildTree(Node);
}
}
</script>
</head>
<body>
<span id=news_ticker style=”position:relative;”></span>
</body>
</html>

–ticker_trial3.xml
<?xml version=”1.0″ encoding=”iso-8859-1″?>
<ticker>
<tickeritem URL=”http://www.nhl.com” target=”_blank”>
<date>March 18, 2004</date>
<name>Marc</name>
<title>President of this country”</title>
<topic>”Hopefully this works”</topic>
</tickeritem>
<tickeritem URL=”http://www.cnn.com” target=”_
blank”>
<date>April 25,2004</date>
<name>Anthony</name>
<title>NEW HTML and XML GURU</title>
<topic>”Atempting this one”</topic>
</tickeritem>
</ticker>

Thanks,
Anthony

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FangFeb 01.2004 — buildTree(ticker); //pass variable not string
Copy linkTweet thisAlerts:
@AcemanauthorFeb 01.2004 — That is great news (? considering i tried that many times, but i must have altered something else at the same time -- so it works thank you!)

NOW....maybe im not seeing what i wrote very well but i want it to take the first child node and display that...pause 5 sec then erase that and put up the next node.

e.g.

March 18, 2004

Marc

President of this country

"Hopefully this works"

5 sec goes by and then it switches that part out and puts in this one:

April 25,2004

Anthony

NEW HTML and XML GURU

"Atempting this one"

--It looks like the code only needs 3 lines:

1. to set the timeout variable

2. to set a loop

3. to ?

but im not sure where to put this or how to word it! ?

What do you think?

OR-------

instead of the switching out after 5 sec -- have them scroll like a news scroller --- but i am not very good at getting that part to work all that well -- i viewed some sites that showed code for how to do it but i just didn't catch on (sounds SAD i know). :rolleyes:

Anthony
Copy linkTweet thisAlerts:
@FangFeb 01.2004 — This will load a scroller with the xml data (needs a few more entries to work)

Stop/start the scroller with mouseover/out or scroll buttons.

The scroll uses "scrollTop" for scrolling.

css hides the natural scrollbar. Size of scroll window is easily changed.
Copy linkTweet thisAlerts:
@AcemanauthorFeb 02.2004 — I appreciate that last one you gave but that really wasn't quite what i wanted -- but is there a part of code to add to my original to make it like a ticker...

---Put this data on the page for 5or7 seconds---

---(tickeritem(0))

March 18, 2004

Marc

President of this country

"Hopefully this works"

---5 sec goes by and then it clears out and puts in this one:---

---(tickeritem(1))

April 25,2004

Anthony

NEW HTML and XML GURU

"Atempting this one"

---when that time is up, then it starts over again---

and during its [B]pausing[/B] you can mouseover to show the link to a website (of course this can be part of the <span>.

That is why i could not figure out where to put a timeout (pause) command within my code to have it read the first node (tickeritem(0)), grab the 4 parts, then display it for some amount of seconds, then clear that out and grab the next node's (tickeritem(1)) 4 parts.

Anthony
Copy linkTweet thisAlerts:
@FangFeb 02.2004 — Scrolls entry, waits 5 seconds, gets next entry and loops to start after last entry.

mouseover/out to stop/start ticker.

var Tableheight may need adjusting if font-size etc. is altered.
×

Success!

Help @Aceman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...