Bronach
08-23-2010, 10:30 AM
Im having an issue with this particular script. i am pulling data form an XML though Javascript and dynamically posting to a table. When pulling this data..IE see's the #text node(ignores it) and continues to load the page. mozillla is a different option. i cant seem to get it to pull from the right nodes! it keeps telling me the value is null. GRRR
I have entered the try...catch to see if i could bypass it. The H and J variable are also a desparate attempt. If anyone could give me any ideas it would be helpfull.
here is my XML
<?xml version="1.0" encoding="utf-8"?>
<holder>
<pics>
<employee>
<picture>pics/Noah Wallace.png</picture>
<name>Noah Wallace</name>
<jobtitle>Technical Services Analyst III</jobtitle>
</employee>
<employee>
<picture>pics/Mike Chan.png</picture>
<name>Michael Chan</name>
<jobtitle>1</jobtitle>
</employee>
<employee>
<picture>pics/Steve Strayer.png</picture>
<name>Steve Strayer</name>
<jobtitle>Manager</jobtitle>
</employee>
</pics>
</holder>
And here is my script...
<body>
<table id="tableID"></table>
<div>
<script type="text/javascript">
function writeXMLData(xdoc)
{
var employee=xdoc.getElementsByTagName("employee");
var name=xdoc.getElementsByTagName("name");
var picture=xdoc.getElementsByTagName("picture");
var tablebdy=document.getElementById("tableID");
for (x=0;x<employee.length;x++){
var eeTable=document.getElementById("tableID");
eeTable.appendChild(document.createElement("tBody"));
for(i=0;i<employee[x].childNodes.length;i++){
var table=eeTable.getElementsByTagName("tBody");
var row=table[x].insertRow(i);
var cell=row.insertCell(0);
try{
if(i==0){
var pEl=document.createElement("img");
pEl.src=employee[x].childNodes[i].firstChild.nodeValue;
cell.appendChild(pEl);}
if(i!=0){
var pEl=document.createTextNode(employee[x].childNodes[i].firstChild.nodeValue);
cell.appendChild(pEl);
}
}
catch(e){
if(i==0){
var j=i+1;
var pEl=document.createElement("img");
pEl.src=employee[x].childNodes[j].firstChild.nodeValue;
cell.appendChild(pEl);
}
if(i!=0){
var h=i+1;
var pEl=document.createTextNode(employee[x].childNodes[h].firstChild.nodeValue);
cell.appendChild(pEl);
}
}
}
}
}
if( ! CJL_loadXmlDocument("xml.xml", writeXMLData) )
{
e.appendChild(document.createElement("td")).innerHTML =
"Browser doesn't support external XML loading";
}
</script>
Thanks
I have entered the try...catch to see if i could bypass it. The H and J variable are also a desparate attempt. If anyone could give me any ideas it would be helpfull.
here is my XML
<?xml version="1.0" encoding="utf-8"?>
<holder>
<pics>
<employee>
<picture>pics/Noah Wallace.png</picture>
<name>Noah Wallace</name>
<jobtitle>Technical Services Analyst III</jobtitle>
</employee>
<employee>
<picture>pics/Mike Chan.png</picture>
<name>Michael Chan</name>
<jobtitle>1</jobtitle>
</employee>
<employee>
<picture>pics/Steve Strayer.png</picture>
<name>Steve Strayer</name>
<jobtitle>Manager</jobtitle>
</employee>
</pics>
</holder>
And here is my script...
<body>
<table id="tableID"></table>
<div>
<script type="text/javascript">
function writeXMLData(xdoc)
{
var employee=xdoc.getElementsByTagName("employee");
var name=xdoc.getElementsByTagName("name");
var picture=xdoc.getElementsByTagName("picture");
var tablebdy=document.getElementById("tableID");
for (x=0;x<employee.length;x++){
var eeTable=document.getElementById("tableID");
eeTable.appendChild(document.createElement("tBody"));
for(i=0;i<employee[x].childNodes.length;i++){
var table=eeTable.getElementsByTagName("tBody");
var row=table[x].insertRow(i);
var cell=row.insertCell(0);
try{
if(i==0){
var pEl=document.createElement("img");
pEl.src=employee[x].childNodes[i].firstChild.nodeValue;
cell.appendChild(pEl);}
if(i!=0){
var pEl=document.createTextNode(employee[x].childNodes[i].firstChild.nodeValue);
cell.appendChild(pEl);
}
}
catch(e){
if(i==0){
var j=i+1;
var pEl=document.createElement("img");
pEl.src=employee[x].childNodes[j].firstChild.nodeValue;
cell.appendChild(pEl);
}
if(i!=0){
var h=i+1;
var pEl=document.createTextNode(employee[x].childNodes[h].firstChild.nodeValue);
cell.appendChild(pEl);
}
}
}
}
}
if( ! CJL_loadXmlDocument("xml.xml", writeXMLData) )
{
e.appendChild(document.createElement("td")).innerHTML =
"Browser doesn't support external XML loading";
}
</script>
Thanks