9, July 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 843 times)
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6274
38470 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 : 4th of July Lottery from TemplateMonster.com
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6274
38470 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 : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7943
40607 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
Promote your blog for free.... Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6274
38470 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 : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7943
40607 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
Promote your blog for free.... Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6274
38470 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 : 4th of July Lottery from TemplateMonster.com
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?
Jul 09, 2008, 11:38:49 AM





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: 35.587
Total Topics: 7.355
Total Members: 3.661
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: komrad

36 Guests, 3 Users online :

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