When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
Print this page.
Published: Wednesday, August 09, 2000

Parsing WML into HTML, Part 2

By Thomas Winningham

  • Read Part 1

  • In Part 1 we looked at how to use ASPTear to grab the headlines from Slashdot in XML form. In this part we will look at the source to parse the WML version of Slashdot's article list. You'll notice a few things:

      - continued -

    • My use of ASPTear instead of the XMLDOC.load to get the WML file.
    • My use of random numbers which create a unique but harmless extraneous url - slashdot.wml?random=23048 - to overcome caching by ASPTear, and c) parsing of WML just like XML.

      response.buffer = true 
      Response.ExpiresAbsolute = Now() - 1
      Response.AddHeader "Cache-Control", "private"
      Set XMLdoc = Server.CreateObject( "Microsoft.XMLDOM" ) 
      Set xObj = Server.CreateObject("SOFTWING.AspTear")
      'start the random number generator
      'generate a nice random number
      randomnum = cstr(Int((100 - 10 + 1) * Rnd + 10))
      'get the WML, using a random number to produce a unique
      'url to prevent caching
      strRetVal = xObj.Retrieve("http://slashdot.org/slashdot.wml" & _
                        "?random=" & _randomnum,Request_GET,"","","")
      set xobj = nothing
      'process the WML, and make a link for each article
      if xmldoc.loadxml(strRetVal) then
        response.write "<html><body>"
        response.write "Current Slashdot Articles:<p>"
        XSLString = "wml/card/p/select/*"
        Set oNodeList = xmlDoc.selectNodes(XSLString)
        'for each article, lets just make a link
        For Each Item in oNodeList
          response.write "<a href="""
          response.write "showarticle.asp?url=" & _
          response.write """>"
          response.write Item.text
          response.write "</a>"
          response.write "<br>" & vbcrlf
        response.write "</body></html>"
        set xmldoc = nothing
        response.write "nope."
        response.write "</body></html>"
        set xmldoc = nothing
      end if

    This produces an output like this:

    Current Slashdot Articles:
    Linux In A Box
    HP Plans The Uber-Calculator
    Transmeta Testing Mass Production
    Windows ME - The End Of UMSDOS And BeOSfs Over Vfat?
    Hacker Crackdown?
    File Packaging Formats - What To Do?
    Sir Alec Guinness Dies
    New Images Of Titan's Surface Released
    HelixCode Releases Admin Tools
    Sega Shutting Down Hundreds Of ROM Sites

    Which is great for using a HTML to Email service like Grabpage or Speedylink. Now, HTML is a markup language just like XML and WML are. It's all just tags. I have found that most web browsers are rather forgiving, as are HTML to Email services, so in the last block of code, we like each article to a file called showarticle.asp, which simply displays the WML without any modification. Most web browsers seem to display this with little problem, and both email services I mentioned do too. Here's the code for the showarticle.asp:

      response.buffer = true
      Response.ExpiresAbsolute = Now() - 1
      Response.AddHeader "Cache-Control", "private"
      'get the article url from the url to launch this .ASP document
      thisarticle = request("url")
      Const Request_POST = 1
      Const Request_GET = 2
      Set xObj = Server.CreateObject("SOFTWING.AspTear")
      randomnum = cstr(Int((100 - 10 + 1) * Rnd + 10))
      strRetVal = xObj.Retrieve("http://slashdot.org" & thisarticle & _
                           "&random=" & randomnum,Request_GET,"","","")
      set xobj = nothing  'Clean up!!
      response.write strRetVal 'basically, just write the straight WML to the browser

    As you can see, we're basically getting the WML, and displaying it. The purpose for this, is that since we are circumventing WML as a reusable resource for raw data, we need to realize that most browsers upon seeing the .WML will try to save or otherwise not display it. It is essentially text, and we can grab it from the server for processing. An example output of this code is here:

    Linux In A Box
    Henrik pointed us to the Linux in a Box project, which is a bitchin' little project to create an inexpensive little Linux box: it boots a 2.0.36 kernel from a ramdisk, and it's pingable and Telenetable, as well as being usable as a Web server. Only for the brave of heart and willing to hack.

    The Palm interface (http://slashdot.org/palm) to Slashdot goes further than the WML to also offer the top 10 comments from users, and honestly I've started using it as my Slashdot fix while on the road. It's reasonably current lately, and is of course a great read.

    So, as you can see, WML is a valuable resource even though it is intended for wireless devices. The Internet's trend to XML has been somewhat encouraged by WML, and we should observe the data portability that WML can still offer, since it essentially is just XML data. Again, a good way to avoid ASPTear or ISP caching is to use random number generators to add extra url strings (that will be ignored by the remote scripts usually), and the Microsoft XMLHTTPREQUEST is currently broken for use in server side applications. Thanks for reading!

  • By Thomas Winningham

    All trademarks and copyrights on this page are owned by their respective owners. Slashdot Comments are owned by the Poster. The Rest of the Slashdot content is 1997-2000 Andover.Net.

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article