473,378 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

ASP Using XML Problem

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>


Jul 19 '05 #1
5 5806
ljb
You are making your life too hard. Use XSL to output the table. You will
need a variation of this using MSXML 4.0

Set xml = CreateObject("Msxml2.DOMDocument.4.0")
Set xsl = CreateObject("Msxml2.DOMDocument.4.0")

xml.async = False
xsl.async = false

xml.Load "xmldata.xml"
xsl.Load "name table.xsl"

set ofile = CreateObject("ADODB.Stream")
ofile.Type = 2
ofile.Charset = "Windows-1252"
ofile.LineSeparator = -1
ofile.open

xml.transformNodeToObject xsl, ofile 'produces UTF-8

ofile.SaveToFile "name table.htm", 2
"Matt" <ma*******@hotmail.com> wrote in message
news:uZ**************@TK2MSFTNGP12.phx.gbl...
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>

Jul 19 '05 #2
ljb
I'm not sure I understand your question. ASP is used to generate an HTML or
other stream that is sent to the requesting application. The whole HTML
document is generated with each request. Perhaps some of it could come from
include files that don't change.

I'm not an expert in XML/XSL. They are over in the microsoft.public.xsl news
group. However I use it whenever I can. Perhaps xml.transformNodeToObject or
something similar could be directed to a response.write and a file not
created.

You should be able to run the vbscript from my earlier message and this XSL
file from your desktop and experiment with it. If your level numbers change
the XSL will need to be adjusted unless someone can show us a more generic
way of doing it and I'm sure someone can.

------------"name table.xsl"-------------

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-microsoft-com:xslt">

<xsl:output method="html" encoding="UTF-8" indent="yes" />

<xsl:template match="/">
<html>
<body>
<table>

<xsl:for-each select="//level3">
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="value" /></td>
</tr>
</xsl:for-each>

</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
Jul 19 '05 #3
When I try to run, there is error for 'Msxml2.DOMDocument.4.0'

Microsoft VBScript runtime (0x800A01AD)
ActiveX component can't create object: 'Msxml2.DOMDocument.4.0'

any ideas?
Jul 19 '05 #4
Are you sure you have MSXML4 installed?

Try "Msxml2.DOMDocument"

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"Matt" <an*******@discussions.microsoft.com> wrote in message
news:23**********************************@microsof t.com...
When I try to run, there is error for 'Msxml2.DOMDocument.4.0'

Microsoft VBScript runtime (0x800A01AD)
ActiveX component can't create object: 'Msxml2.DOMDocument.4.0'

any ideas?

Jul 19 '05 #5
ljb
Try Msxml2.DOMDocument.3.0 or Msxml2.DOMDocument. If you have IE6 installed
you should have MSXML3 also. I verified the transform works in 3 but some
earlier versions of MSXML will not.

"Matt" <an*******@discussions.microsoft.com> wrote in message
news:23**********************************@microsof t.com...
When I try to run, there is error for 'Msxml2.DOMDocument.4.0'

Microsoft VBScript runtime (0x800A01AD)
ActiveX component can't create object: 'Msxml2.DOMDocument.4.0'

any ideas?

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Aaron Prohaska | last post by:
I have just run into a problem where I have a page that posts back to itself to execute code, except when the page does the post back it somehow executes code that is in our home page for the site....
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
12
by: bj7lewis | last post by:
I am working on a project I want to add a few files as resource to access(copy them to FS and use) at runtime. So far in VS.NET IDE, I Add Files to the project and set its Build Action to...
4
by: zubair | last post by:
Hello everyone! I have uploaded my site on a webserver. Some times it works fine but some time it gives error "Null Object reference exception". The same site on my local server works just fine. ...
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
20
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
5
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.