So, I've been learning XML/JavaScript now for like... 4 days...I think I've been doing ok, I've downloaded several books on JavaScript and XML but I stuck on this issue...
Basically I'm trying to show a table of XML data, but I'd like to group the data ...but a category which is a node of the XML itself...here is my XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ACCESSORIES xmlns:html="<ITEMS>
<ITEM>
<ITEMNUMBER>5709A007AA</ITEMNUMBER>
<DESCRIPTION>Cabinet-V1</DESCRIPTION>
<MACHINEMODEL>iR1025/iR1025N/iR1025iF</MACHINEMODEL>
<COMMENTS></COMMENTS>
<CATEGORY>1</CATEGORY>
</ITEM>
</ITEMS>
</ACCESSORIES>
and here is the java script that builds that table:
<script type="text/javascript">
var xmlDoc=null;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{// code for Firefox, Mozilla, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load("1025_3.xml");
document.write("<table width='800' align='center' border='1'>");
document.write("<tr>");
document.write("<td align='center' width='100'>");
document.write("<strong>Item Number</strong>");
document.write("</td>");
document.write("<td align='center' width='500'>");
document.write("<strong>Description</strong>");
document.write("</td>");
document.write("<td align='center' width='200'>");
document.write("<strong>Models</strong>");
document.write("</td>");
document.write("</tr>");
var x=xmlDoc.getElementsByTagName("ITEM");
for (var i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td align='center'>");
document.write(x.getElementsByTagName("ITEMNUMBER")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(x.getElementsByTagName("DESCRIPTION")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(x.getElementsByTagName("MACHINEMODEL")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
var x=xmlDoc.getElementsByTagName("ITEM");
---> ?????? <--- I believe I need to create a grouping rule here for my next group...
for (var i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td align='center'>");
document.write(x.getElementsByTagName("ITEMNUMBER")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(x.getElementsByTagName("DESCRIPTION")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(x.getElementsByTagName("MACHINEMODEL")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
}
</script>
I put a comment in the middle of the code...with regards to what I believe I need to do...but I'm at a loss on this one...
Any thoughts would be great...
If I do find an answer, I'll post the code...as I'll continue to search for a solution to this problem.
Thanks again.
Eddie
Basically I'm trying to show a table of XML data, but I'd like to group the data ...but a category which is a node of the XML itself...here is my XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ACCESSORIES xmlns:html="<ITEMS>
<ITEM>
<ITEMNUMBER>5709A007AA</ITEMNUMBER>
<DESCRIPTION>Cabinet-V1</DESCRIPTION>
<MACHINEMODEL>iR1025/iR1025N/iR1025iF</MACHINEMODEL>
<COMMENTS></COMMENTS>
<CATEGORY>1</CATEGORY>
</ITEM>
</ITEMS>
</ACCESSORIES>
and here is the java script that builds that table:
<script type="text/javascript">
var xmlDoc=null;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{// code for Firefox, Mozilla, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load("1025_3.xml");
document.write("<table width='800' align='center' border='1'>");
document.write("<tr>");
document.write("<td align='center' width='100'>");
document.write("<strong>Item Number</strong>");
document.write("</td>");
document.write("<td align='center' width='500'>");
document.write("<strong>Description</strong>");
document.write("</td>");
document.write("<td align='center' width='200'>");
document.write("<strong>Models</strong>");
document.write("</td>");
document.write("</tr>");
var x=xmlDoc.getElementsByTagName("ITEM");
for (var i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td align='center'>");
document.write(x.getElementsByTagName("ITEMNUMBER")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(x.getElementsByTagName("DESCRIPTION")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(x.getElementsByTagName("MACHINEMODEL")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
var x=xmlDoc.getElementsByTagName("ITEM");
---> ?????? <--- I believe I need to create a grouping rule here for my next group...
for (var i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td align='center'>");
document.write(x.getElementsByTagName("ITEMNUMBER")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(x.getElementsByTagName("DESCRIPTION")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(x.getElementsByTagName("MACHINEMODEL")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
}
</script>
I put a comment in the middle of the code...with regards to what I believe I need to do...but I'm at a loss on this one...
Any thoughts would be great...
If I do find an answer, I'll post the code...as I'll continue to search for a solution to this problem.
Thanks again.
Eddie