M
Matt
I want the ASP page retrieves data from XML file and put in table. However,
is it possible that the ASP code doesn't know the look of XML file
structure? The following is my ASP code and XML data file. If more levels
are added in XML file, I need to change ASP code as well. i.e. For every
additional level in XML file, I need to add an additional loop in ASP page.
My question is: is it possible that ASP code is unchanged, even XML file
structure has changed. I just want the ASP code traverses the XML file can
print out all data in the table.
Please advise. Thanks!
==============================================================
<%
Sub GetXMLData(link)
Dim xml
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.load(Server.MapPath(link))
Dim root
Set root = xml.documentElement
%>
<table border="1">
<th>name</th><th>value</th>
<tbody>
<%
Dim name, url, thisChild
For I = 0 TO (root.childNodes.length - 1) '# level2
Set thisChild = root.childNodes(I)
For J = 0 TO (thisChild.childNodes.length - 1) '# level 3
Set thisChild2 = thisChild.childNodes(J)
name = thisChild2.childNodes(0).Text
value = thisChild2.childNodes(1).Text
%>
<TR><TD><%= name %></TD><TD><%= value %></TD></TR>
<% Next %>
<% Next %>
</tbody></table>
<%
End Sub
%>
<%
Call GetXMLData("xmldata.xml")
%>
==============================================================
<!-- xmldata.xml -->
<?xml version="1.0"?>
<level1>
<level2>
<level3>
<name>name1</name>
<value>value1</value>
</level3>
<level3>
<name>name2</name>
<value>value2</value>
</level3>
</level2>
<level2>
<level3>
<name>name3</name>
<value>value3</value>
</level3>
</level2>
</level1>
is it possible that the ASP code doesn't know the look of XML file
structure? The following is my ASP code and XML data file. If more levels
are added in XML file, I need to change ASP code as well. i.e. For every
additional level in XML file, I need to add an additional loop in ASP page.
My question is: is it possible that ASP code is unchanged, even XML file
structure has changed. I just want the ASP code traverses the XML file can
print out all data in the table.
Please advise. Thanks!
==============================================================
<%
Sub GetXMLData(link)
Dim xml
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.load(Server.MapPath(link))
Dim root
Set root = xml.documentElement
%>
<table border="1">
<th>name</th><th>value</th>
<tbody>
<%
Dim name, url, thisChild
For I = 0 TO (root.childNodes.length - 1) '# level2
Set thisChild = root.childNodes(I)
For J = 0 TO (thisChild.childNodes.length - 1) '# level 3
Set thisChild2 = thisChild.childNodes(J)
name = thisChild2.childNodes(0).Text
value = thisChild2.childNodes(1).Text
%>
<TR><TD><%= name %></TD><TD><%= value %></TD></TR>
<% Next %>
<% Next %>
</tbody></table>
<%
End Sub
%>
<%
Call GetXMLData("xmldata.xml")
%>
==============================================================
<!-- xmldata.xml -->
<?xml version="1.0"?>
<level1>
<level2>
<level3>
<name>name1</name>
<value>value1</value>
</level3>
<level3>
<name>name2</name>
<value>value2</value>
</level3>
</level2>
<level2>
<level3>
<name>name3</name>
<value>value3</value>
</level3>
</level2>
</level1>