SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot RyaninZion's Avatar
    Join Date
    Jul 2003
    Location
    Jerusalem
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML file directory

    I have a flat-file folder structure for my xml files (articles). I want to have an index page in each of the particular folder categories that dynamically lists all of the xml files in the folder, outputting the <headline> field, <date> field and the url.

    I tried doing this with an asp script, which worked fine for listing html and asp files, but it wouldn't read the xml files.

    Can anyone offer some direction on how to accomplish this?

    Thanks in advance.

  2. #2
    SitePoint Zealot RyaninZion's Avatar
    Join Date
    Jul 2003
    Location
    Jerusalem
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I found a way to do what I want with this script:

    <%
    Server.ScriptTimeOut = 300
    strListFolder = "."
    %>

    <%
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objFolder = objFSO.GetFolder(Server.MapPath(strListFolder))
    Set colFiles = objFolder.Files

    For Each objFile in colFiles

    strFileType = objFSO.GetExtensionName(objFile.Name)
    strPathType = objFSO.GetFileName(objFile.Name)
    If (Left(strPathType, 2) = "ed") And (strFileType = "xml") Then

    Set objStream = objFile.OpenAsTextStream(1)
    strContent = objStream.ReadAll
    objStream.Close

    strTitle = ""
    intStart = Instr(UCase(strContent), "<HEADLINE>") + 10
    intFinish = Instr(UCase(strContent), "</HEADLINE>")
    If (intStart > 0) And (intFinish > intStart) Then
    strTitle = Trim(Mid(strContent, intStart, intFinish - intStart))
    End If
    If Len(strTitle) = 0 Then strTitle = "Untitled page '" & objFile.Name & "'"

    strDate = ""
    intStart = Instr(UCase(strContent), "<DATE>") + 6
    intFinish = Instr(UCase(strContent), "</DATE>")
    If (intStart > 0) And (intFinish > intStart) Then
    strDate = Trim(Mid(strContent, intStart, intFinish - intStart))
    End If

    strThisFileURL = strListFolder & objFile.Name
    strLink = "<A HREF=" & Chr(34) & strThisFileURL _
    & Chr(34) & ">" & strTitle & "</A><BR>"
    response.Write "" & (strDate) & "<br />"
    response.Write "" & (strLink) & "<br />"
    End If
    Next
    %>

    Now I just need to know how to display the list of files starting with the newest rather than the oldest.... Any tips?

  3. #3
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Create a disconnected Recordset outside the loop, add fields for headline, date, time, etc then inside the loop add a new records for each XML file.

    Then use the .Sort property to sort the results in to the required order, and loop through the sorted recordset to display the data in the format you require.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


Bookmarks

Posting Permissions

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