22, November 2008

parsing xml with javascript - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  JavaScript
Topic: parsing xml with javascript
« previous next »
Pages: [1] Print

Author Topic: parsing xml with javascript  (Read 997 times)
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6441
39470 credits
Members referred : 374


It's time to use PHP5!


« on: Apr 28, 2006, 10:13:03 AM »

Hello,

just started an example to parse a simple xml structure, but I'm getting an "undefind" in the beginning using this code (w3schools):
Code:
<html>
<head>
<script type="text/javascript">
var xmlDoc;
var tplstrings;
function loadXML(file) {
if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(file);
getstrings();
} else if (document.implementation && document.implementation.createDocument) {
xmlDoc= document.implementation.createDocument("","",null);
xmlDoc.load(file);
xmlDoc.onload=getstrings;
} else {
return;
}
}
function getstrings() {
tplstrings = "loaded xml data";
}
</script>
</head>

<body onLoad="loadXML('test3.xml')">
  <script type="text/javascript">document.write(tplstrings);</script>
</body>
</html>

and this is the xml file:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<featured>
  <template>10598</template>
  <template>10806</template>
  <template>10805</template>
  <template>10807</template>
</featured>

What's wrong anyone an idea?


Last blog : Just a better Internet portal provided by Google
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6441
39470 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Apr 28, 2006, 12:17:37 PM »

got it working:
Cool

Code:
<html>
<head>
<script type="text/javascript">
var xmlDoc;

function loadXML(file) {
if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(file);
getstrings()
} else if (document.implementation && document.implementation.createDocument) {
xmlDoc= document.implementation.createDocument("","",null);
xmlDoc.load(file);
xmlDoc.onload=getstrings
} else {
return;
}
}
function getstrings() {
tpls = xmlDoc.getElementsByTagName("template");
for (x = 0; x < tpls.length; x++) {
document.getElementById("test").innerHTML += tpls[x].firstChild.nodeValue;
}
}
</script>
</head>

<body onLoad="loadXML('test3.xml')">
  <div id="test"></div>
</body>
</html>



Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8250
42487 credits
Members referred : 3



« Reply #2 on: Apr 28, 2006, 12:52:05 PM »

Hehe you are fast.

You found the solution before I even read your post Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6441
39470 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Apr 28, 2006, 12:55:47 PM »

hehe, Javascript is still tricky to me but I made it:

http://www.all4yourwebsite.com/mod.htm Visit through proxy

my first kind of ajax type tool...


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8250
42487 credits
Members referred : 3



« Reply #4 on: Apr 28, 2006, 01:02:50 PM »

Cool tool. I guess that you will see it in many template monster affiliate sites now....

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6441
39470 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Apr 28, 2006, 01:11:06 PM »

Cool tool. I guess that you will see it in many template monster affiliate sites now....
no, its actually a module for google: http://www.googlemodules.com/module/592/ Visit through proxy


Last blog : Just a better Internet portal provided by Google
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=2377
Tags : javascript design affiliate xml Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  JavaScript
Topic: parsing xml with javascript
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Nov 22, 2008, 10:24:39 PM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 37.741
Total Topics: 7.651
Total Members: 4.398
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: egseopro

41 Guests, 3 Users online :

11 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.