Print Page | Close Window

asp xml question

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=23493
Printed Date: 29 March 2026 at 4:18pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: asp xml question
Posted By: KCWebMonkey
Subject: asp xml question
Date Posted: 08 June 2007 at 6:05pm

<%
 set objSrvHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
 objSrvHTTP.open "GET", url, False, var_user, var_password
 objSrvHTTP.setRequestHeader "Content-Type", "application/xml"
 objSrvHTTP.setRequestHeader "Accept", "application/xml"
 objSrvHTTP.send
 Response.ContentType = "application/xml" 
 response.Write(objSrvHTTP.responseText)
%>

 
I need tips on how to parse this XML response and display it as html data in a browser... can someone point me in the right direction?
 
example of XML response
 

<?xml version="1.0" encoding="UTF-8" ?>
<projects>
  <project>
    <announcement />
    <created-on type="date">2007-05-25</created-on>
    <id type="integer">1108936</id>
    <last-changed-on type="datetime">2007-06-04T15:08:52Z</last-changed-on>
    <name>Project #1</name>
    <show-announcement type="boolean">false</show-announcement>
    <show-writeboards type="boolean">true</show-writeboards>
    <start-page>log</start-page>
    <status>archived</status>
    <company>
      <id type="integer">621101</id>
      <name>company #1</name>
    </company>
  </project>
  <project>
    <announcement>this is the description of the project</announcement>
    <created-on type="date">2007-05-30</created-on>
    <id type="integer">1117122</id>
    <last-changed-on type="datetime">2007-06-05T19:30:27Z</last-changed-on>
    <name>Project #2</name>
    <status>active</status>
    <company>
      <id type="integer">621101</id>
      <name>company #1</name>
    </company>
  </project>
</projects>



Replies:
Posted By: WebWiz-Bruce
Date Posted: 08 June 2007 at 6:36pm
You could use ASP to replace the XML with HTML and format it that way, or you could use an XSLT stylesheet to format your HTML.

I quite like XSLT but browsers are very strict on it, you can get away with typos and omissions like you can with HTML.


-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: KCWebMonkey
Date Posted: 08 June 2007 at 6:50pm
i'll read up on xslt then. thanks for the suggestion.


Posted By: KCWebMonkey
Date Posted: 08 June 2007 at 8:14pm
is there a way to call a childNode by its name instead of its numerical index value?
 
example:
 
objHdl.childNodes("name").text
 
instead of
 
objHdl.childNodes(2).text
 
 
i ask this because the xml response i get sometimes doesn't have all the same nodes... and if one is missing, then the index value for all the others is wrong...


Posted By: WebWiz-Bruce
Date Posted: 08 June 2007 at 9:56pm
It's been a while since I messed with XSLT but I'm sure you can refernce by name.

Have a look at the XSLT stylesheet used in Web Wiz Forums for the RSS Feeds, it will hopefully give you some clues.


-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: Sumea
Date Posted: 16 July 2007 at 1:36am
Do an xsl transform, rather than parsing it...

<%

Dim xml
    Set xml = Server.CreateObject("Msxml2.DomDocument")
    xml.async = False
    xml.load (Server.Mappath("yourxmlfile.xml"))

Dim xsl
    set xsl = Server.CreateObject("Msxml2.DomDocument")
    xsl.async = false
    xsl.load(Server.MapPath("yourxslfile.xsl"))

'Response.Write XML.transformNode(XSL)

%>

point yourxmlfile.xml to the xml file you posted, and for the xsl style sheet (yourxslfile.xsl), do something like..

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>

<xsl:template match="projects">
<html><body>
<h2><xsl:value-of select="name"/></h2>
<p><xsl:value-of select="created-on"/> - <xsl:value-of select="last-changed-on"/></p>
</body></html>
</xsl:template>

</xsl:stylesheet>
(the xsl I've made is a brief example of what you can do. You can add more values, insert html to make it look presentable etc)




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net