Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 14th, 2005, 10:26 PM
Authorized User
 
Join Date: Jan 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML and JavaScript

what i am trying to do is by using javascript i am trying to create a table using the information in a xml file ... i have truncated the javascript code to show only the part that i would use to create the header for the table...

the html code....

<html>

<head>
<Script type="text/javascript">

var IE=(navigator.appName.indexOf("Explorer")>-1);

if(IE)
{

var xmlDoc=new ActiveXObject("MICROSOFT.XMLDOM");
xmlDoc.async=false;
}
else
{
var xmlDoc=document.implementation.createDocument(""," doc",null);
}

xmlDoc.load("xml1.xml");

function xmlTable()
{

var papaNode=xmlDoc.getElementsByTagName("child");

//The Table

var tableElement=document.createElement("TABLE");
var tableRow=document.createElement("TR");

//Table Header

for(i=0;i<papaNode[0].childNodes.length;i++)
{

if(papaNode[0].childNodes[i].nodeType!=1)continue;

var tableCell=document.createElement("TH");
var theText=document.createTextNode(papaNode[0].childNodes[i].nodeName);
tableCell.appendChild(theText);
tableRow.appendChild(tableCell);

}

tableElement.appendChild(tableRow);
document.getElementById("p1").appendChild(tableEle ment);


}

</script>
</head>

<body>

<a href="javascript:xmlTable()">xml table</a>
<br>
<p id="p1"></p>

</body>
</html>

and the XML file(xml1.xml) is...

<?xml version="1.0" encoding="ISO-8859-1"?>

<group>
   <child>
    <name>Glen Benton</name>
    <age>13</age>
    <class>1B</class>
   </child>
   <child>
    <name>Sean Reinhardt</name>
    <age>12</age>
    <class>1B</class>
   </child>
   <child>
    <name>Angel Ripper</name>
    <age>14</age>
    <class>2C</class>
   </child>
</group>


the problem with the above code is that ... when i click on the link "xml table" no data is displayed in the page ... where could i have gone wrong
the header part of the table should look like this...

+------------------------------+
| name | age | class |
+------------------------------+


 
Old March 14th, 2005, 02:58 PM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I am learning XML (just got trained from LearningTree). I am very interested in what you do as described in your articel. I copy your entire code and save as a html file. When run, it does not show the column headers.

When I separated the XML and XSL and save them as Test.xml and Test.xsl in c:\, then run the html file, it got blank page.

Would you please let me know more detail about how to get your code run?

Thanks

 
Old March 14th, 2005, 03:04 PM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am sorry, I duplicated what you experienced: blank page.






Similar Threads
Thread Thread Starter Forum Replies Last Post
XML in JavaScript for Mozilla jwalborn Javascript 2 February 6th, 2008 11:47 AM
javascript and XML chuck_schuldiner Javascript 3 February 14th, 2005 11:08 AM
xml & javascript shine XML 1 December 24th, 2003 12:45 PM
XML DOM and Javascript lilu XML 3 September 25th, 2003 07:55 AM
XML, XML Schema, JavaScript, ASP cyberjames2003 XML 0 June 4th, 2003 04:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.