28, May 2012

parsing xml with javascript - webmaster forum

 
Webdigity webmaster forums
[ 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
Instabuck - The easy way to sell digital products online

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


It's time to use PHP5!


« on: Apr 28, 2006, 09: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?

Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Apr 28, 2006, 11:17:37 am »

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>


I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #2 on: Apr 28, 2006, 11:52:05 am »

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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Apr 28, 2006, 11:55:47 am »

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

http://www.all4yourwebsite.com/mod.htm

my first kind of ajax type tool...

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #4 on: Apr 28, 2006, 12: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 or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Apr 28, 2006, 12: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/

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

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?
May 28, 2012, 10:42:19 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!






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