Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP » XML/XSL » Downloads
 
Add your own
alternative version

XML Strengths and Weaknesses with DOM, ASP and XSL

, 11 Mar 2002
Since the inception of XML, many developers have wondered why they need XML and how they can use XML to their benefit. In this article, Nakul looks at some of the terminology that comes with using XML and its related technologies, as well as how to create and transform XML documents with ASP and XSL
xmldom_src.zip
saved.xsl
<%

  'IMPORTANT: Create a system DSN called
  'pubs and link it to the pubs database
  'before continuing

  'Open database connection
  Set conn = Server.CreateObject("ADODB.Connection")
  dsn = "DSN=pubs;UID=sa;PWD="
  conn.Open dsn

  'Create XMLDOM Object
  Dim xmldoc
  Set xmldoc = Server.CreateObject("Microsoft.XMLDOM")

  If (xmldoc.childNodes.length = 0) Then
    ' Build the XML document
    Set root = xmldoc.createNode("element", "Hi-Tech", "")

    xmldoc.appendChild (root)

    ' Queries the database for customer data
    Sql = "select au_lname,au_fname,au_id from authors"
    Set rs = conn.Execute(Sql)
  
    rs.MoveFirst

    'Loop through the recordset
    Do While Not rs.EOF
      Set onode = xmldoc.createNode("element", "Employee", "")
      xmldoc.documentElement.appendChild (onode)
   
      Set inode = xmldoc.createNode("element", "Name", "")
      inode.Text = rs.fields(0) & " " & rs.fields(1)
      onode.appendChild (inode)

      'Grab another recordset based on the authorID
      Sql = "select title_id,royaltyper from titleauthor " & _
            "where au_id = '" &  rs.fields(2) & "'"

      Set rs2 = conn.Execute(Sql)

      If Not (rs2.EOF = True And rs2.bof = True) Then
        Set inode = xmldoc.createNode("element", "Titles", "")
        onode.appendChild (inode)
        Set child = xmldoc.createNode("element", "TitleId", "")
        child.Text = rs2.fields(0)
        inode.appendChild (child)
        Set child = xmldoc.createNode("element", "royalty", "")
        child.Text = rs2.fields(1)
        inode.appendChild (child)

        rs2.Close
        Set rs2 = Nothing
      End If
   
      rs.movenext
    Loop

    Set rs = Nothing
  End If

  'Save the XML doc
  xmldoc.save server.mappath("saved.xml")

  '------ DISPLAY THE XML DATA ------------
  ' Linking XML and XSL together
  sourceFile = Server.MapPath("saved.xml")
  styleFile = Server.MapPath("saved.xsl")
  
  set source = Server.CreateObject("Microsoft.XMLDOM")
  source.async = false
  source.load(sourceFile)
  set style = Server.CreateObject("Microsoft.XMLDOM")
  style.async = false
  style.load(styleFile)
  Response.Write source.transformNode(style)

%>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Nakul Goyal
Web Developer
United States United States
Nakul Goyal, currently doing Master of Sciences in Information Technology from Panjab University, Chandigarh. A Bachelor of Computer Applications from Punjab Technical University, he is passionate towards the Cyber World & he likes to write about Technology. He's also a Microsoft Certified Professional and a Brainbench Certified 'MVP'(Most Valuable Professional). Also the Co-Founder of CWSTeam (http://www.cwsteam.com). Contact Nakul Goyal by Email: nakul@cwsteam.com

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 12 Mar 2002
Article Copyright 2002 by Nakul Goyal
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid