Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > ASP Using XML Problem

Reply
Thread Tools

ASP Using XML Problem

 
 
Matt
Guest
Posts: n/a
 
      02-19-2004
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>




 
Reply With Quote
 
 
 
 
ljb
Guest
Posts: n/a
 
      02-19-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>
>
>
>
>



 
Reply With Quote
 
 
 
 
ljb
Guest
Posts: n/a
 
      02-19-2004
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-microsoft-comslt">

<xslutput 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>


 
Reply With Quote
 
Matt
Guest
Posts: n/a
 
      02-20-2004
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?
 
Reply With Quote
 
Mark Schupp
Guest
Posts: n/a
 
      02-20-2004
Are you sure you have MSXML4 installed?

Try "Msxml2.DOMDocument"

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com


"Matt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?



 
Reply With Quote
 
ljb
Guest
Posts: n/a
 
      02-23-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem to insert an XML-element by XSLT-converting from one XML-file into another XML-file jkflens XML 2 05-30-2006 09:41 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
ASP XML Support - Generate XML string from FORM DATA based on XML schema Matt ASP General 3 04-23-2004 07:12 PM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM
Using One XSLT and multiple XML Problem (One is XML and another one is XBRL) loveNUNO XML 2 11-20-2003 06:47 AM



Advertisments