Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using XML data as href

    I'm rather new to XML, ASP, even HTML, but I'm trying to maintain an intranet. One thing I'd like to do is display a list of 'past stories' as a clickable list (in a table). I've got the XML file already, where the layout is like this:
    <paststories>
    <story>
    <storyref>ref1</storyref>
    <storytitle>title1</storytitle>
    <storydate>date1</storydate>
    </story>
    </paststories>
    Obviously there are many <story> entries!

    So how do I pick this up in an ASP file?
    So far, I have
    <?xml version="1.0" encoding="windows-1252"?>
    <xml src="psfull.xml" id="xmldso" async="false"></xml>
    in the HTML <body> section, where psfull.xml is the name of the XML file.

    Then the table is described like this:
    <table border="1" width="100%" datasrc="#xmldso">
    <thead>
    <th width="65%" height="43">Story</td>
    <th width="35%" align="center" height="43">Posted On</td>
    </thead>
    <tr>
    <td align="left" height="23"><span datafld="storytitle"></span></td>
    <td align="center" height="23"><span datafld="storydate"></span></td>
    </tr>
    </table>

    This coding I have picked up from W3Schools website, but it neither seems to work, and neither does it allow me to substitute <storyref> as the href value.

    Can anyone tell me why the table does not show as coded - and then how I can use the <storyref> values to fill in the href values? Thanks.

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using XML data as href

    This sounds like a job for XSL/XSLT. Check out the XSL/XSLT information on W3Schools and you should find what you need to make this happen.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using XML data as href

    Thanks, Mark. I've now got the data showing in the table as required (didn't check the new xml file in to the development site, did I? Doh!), but of course I still have the question of how to use the <storyref> value as an href value. I'll look into XSL/XSLT as you suggest. Thanks again.

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using XML data as href

    Hi Mark,

    I've looked into XSL/XSLT as you suggested, but I think it's way beyond my level of expertise! I can't find anything that means anything to me. I've also been looking into ReadXML, but despite finding quite a bit about it, everything I try results in the page being unviewable. Trouble is, I'm not sure what I should be declaring in the file, I think. I can use simple XML to present the data just as I want it - except for the href itself. No other ideas? Thanks anyway.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Using XML data as href

    Assuming you haven't already solved this one by now.... using VBScript in your ASP page, you can call Microsoft's MSXML library to extract the data from your XML file. You might also be able to use ADO; I haven't tried that yet.

    Here's some sample VBA code using the XML library to read a file and set the positions of command bars in Outlook. You would do other stuff with the data, but hopefully it provides some insight into extracting the data:
    <pre>Sub CBarRestoreFromXMLlb()
    ' Jefferson Scher 14 Feb 2004 - Late Binding version
    Dim cbar As CommandBar, strArray() As String
    Dim xmlDoc As Object, xmlRoot As Object, xmlCBarNode As Object
    ' Retrieve previously saved XML document
    Set xmlDoc = CreateObject("MSXML.DOMDocument")
    xmlDoc.Load "c:testingOutlookCBars.xml"
    ' Loop through the saved settings and move the toolbars around
    Set xmlRoot = xmlDoc.documentElement
    For Each xmlCBarNode In xmlRoot.childNodes
    Set cbar = Outlook.ActiveExplorer.CommandBars(xmlCBarNode.chi ldNodes(0).Text)
    If Not cbar.Visible Then cbar.Visible = True
    strArray() = Split(xmlCBarNode.childNodes(1).Text, "|")
    cbar.Position = CLng(strArray(0))
    cbar.RowIndex = CLng(strArray(1))
    cbar.Top = CLng(strArray(2))
    cbar.Left = CLng(strArray(3))
    Next
    ' Clean up objects
    If Not (xmlCBarNode Is Nothing) Then Set xmlCBarNode = Nothing
    If Not (xmlRoot Is Nothing) Then Set xmlRoot = Nothing
    If Not (xmlDoc Is Nothing) Then Set xmlDoc = Nothing
    If Not (cbar Is Nothing) Then Set cbar = Nothing
    End Sub</pre>

    Please note: some of this is illegal in VBScript (e.g., declaring the type of a variable), but hopefully a lot of it will translate.

  6. #6
    2 Star Lounger
    Join Date
    Oct 2002
    Location
    Lakewood, New Jersey, USA
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using XML data as href

    In order to make the href of the <a> element have a value from your xml file,
    write
    <a datafld='storyref'>
    when the datafld property is used on the <a> element, it fills the href attribute with its data.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •