Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - asp xml question
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

asp xml question

 Post Reply Post Reply
Author
KCWebMonkey View Drop Down
Senior Member
Senior Member
Avatar
Go Chiefs!

Joined: 21 June 2002
Status: Offline
Points: 1319
Post Options Post Options   Thanks (0) Thanks(0)   Quote KCWebMonkey Quote  Post ReplyReply Direct Link To This Post Topic: asp xml question
    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>
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
KCWebMonkey View Drop Down
Senior Member
Senior Member
Avatar
Go Chiefs!

Joined: 21 June 2002
Status: Offline
Points: 1319
Post Options Post Options   Thanks (0) Thanks(0)   Quote KCWebMonkey Quote  Post ReplyReply Direct Link To This Post Posted: 08 June 2007 at 6:50pm
i'll read up on xslt then. thanks for the suggestion.
Back to Top
KCWebMonkey View Drop Down
Senior Member
Senior Member
Avatar
Go Chiefs!

Joined: 21 June 2002
Status: Offline
Points: 1319
Post Options Post Options   Thanks (0) Thanks(0)   Quote KCWebMonkey Quote  Post ReplyReply Direct Link To This Post 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...
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Sumea View Drop Down
Newbie
Newbie


Joined: 18 September 2006
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote Sumea Quote  Post ReplyReply Direct Link To This Post 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)

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.