新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> XML网站展示,XML源代码,XML编程示例。 本版仅接受原创、转贴、网站展示,具体的技术交流请前往各相关版块。
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XML源码及示例(仅原创和转载) 』 → [求助]ASP+XML怎样生成日志,急 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 4922 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [求助]ASP+XML怎样生成日志,急 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     meiyu_0707 美女呀,离线,快来找我吧!
      
      
      等级:大一新生
      文章:1
      积分:59
      门派:XML.ORG.CN
      注册:2006/3/13

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给meiyu_0707发送一个短消息 把meiyu_0707加入好友 查看meiyu_0707的个人资料 搜索meiyu_0707在『 XML源码及示例(仅原创和转载) 』的所有贴子 引用回复这个贴子 回复这个贴子 查看meiyu_0707的博客楼主
    发贴心情 [求助]ASP+XML怎样生成日志,急


    logInfo.asp
    <%
    function WriteSysLog(sys_userid,sys_username,operate)
      dim op_username
      if trim(sys_userid)="" and trim(sys_username)="" then   
        op_username="匿名"
      else
        op_username = sys_userid & "/" & sys_username
      end if
      
      '日志写入路径xmlPath
      dim xmlPath,xmlFile,RootNode,LogFile,fso,fff,mmm,xd,et,cnode,node2
      xmlPath="LogFile/"
      xmlFile=replace(cstr(ConvertDate(date())),"-","_") & ".xml"
      RootNode="syslog"                  '日志文件根节点名字
      LogFile=server.mappath(xmlPath & xmlFile)  '日志文件路径
      
      set fso=server.CreateObject("scripting.filesystemobject")
      '如果日志文件不存在,就创建一个,并写入头信息和根信息
      if not fso.FileExists(LogFile) then
        fso.CreateTextFile LogFile
        set fff=fso.GetFile(LogFile)
        set mmm=fff.openastextstream(2)
        mmm.write "<?xml version=""1.0"" encoding=""gb2312"" ?>" & vbcrlf & "<?xml-stylesheet type='text/xsl' href='logInfo.xsl'?>" & vbcrlf &  "<" & rootnode & "></" & rootnode & ">"
        set mmm=nothing
        set fff=nothing
      end if  
      set fso=nothing

      Set xd = Server.CreateObject("msxml2.domdocument")   
      xd.async = false   
      xd.load(LogFile)  
      if xd.parseError.errorcode<>0 then  
        WriteSysLog=1   '打开日志文件出错
        exit function
      end if  
      
      '创建新节点信息
      set et=xd.documentElement   
      set cnode=xd.createElement("log")
      et.appendchild(cnode)
      set node2=xd.createElement("username")
      node2.text=op_username
      cnode.appendchild(node2)
      set node2=xd.createElement("operate")
      node2.text=operate
      cnode.appendchild(node2)
      set node2=xd.createElement("userip")
      node2.text=Request.ServerVariables("Remote_Addr")
      cnode.appendchild(node2)
      set node2=xd.createElement("opdate")
      node2.text=cstr(now())
      cnode.appendchild(node2)
      xd.save LogFile   '写入日志文件

      set cnode=nothing
      set node2=nothing
      set xd=nothing
      
      writeSysLog=9  '说明正常写入了日志信息
    end function   

    '获得当前虚拟目录的名字
    function getRoot()
      dim url
      url=Request.ServerVariables("URL")
      url=right(url,len(url)-1)
      getRoot= mid(url,1,instr(url,"/")-1)
    end function

    '将一个一位的数字前面加零
    function FillZero(str)
      dim ttt
      ttt=str
      if len(str)=1 then
        ttt="0" & str
      end if
      FillZero=ttt
    end function
    '转化日期,将 一位补上零  2003-1-2  -->  2003-01-02
    function ConvertDate(tDate)
      dim ttt
      ttt=tDate  
      if isdate(tDate) then
        ttt=year(tDate) & "-" & FillZero(month(tDate)) & "-" & FillZero(day(tDate))
      end if
      ConvertDate=ttt
    end function
    %>

    logInfo.xsl
    <?xml version="1.0" encoding="gb2312"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://www.cccar.com.cn/"
    exclude-result-prefixes="msxsl user">

    <!-- localized strings -->
    <xsl:variable name='ColumnHeader_UserName'>用户</xsl:variable>
    <xsl:variable name='ColumnHeader_Time'>时间</xsl:variable>
    <xsl:variable name='ColumnHeader_Operate'>操作</xsl:variable>
    <xsl:variable name='ColumnHeader_Address'>IP地址</xsl:variable>

    <!-- variables -->
    <xsl:variable name='TableStyle'>background-color:#DAE6D8;font-family:Simsun, Verdana; font-size:75%; text-align:left; vertical-align:top</xsl:variable>
    <xsl:variable name='HeaderStyle'>background:a0b0a8;color:#000000;border-bottom:1 solid black;border-top:1 solid black</xsl:variable>
    <msxsl:script language="javascript" implements-prefix="user">
       function xmlDateTime(nodelist) {
               return Date.parse(nodelist.replace(/-/g,"/"));
            }
    </msxsl:script>
    <xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="syslog">

        <html>
        <head>
            <title>
                日志查看
            </title>
        </head>

        <body style='margin:10;background-color:#DAE6D8'>
            <div align="center">
            <table style="{$TableStyle}" width="100%" align="center" cellspacing='0'>
              
                <thead>
                    <tr height="23">
                        
                        <th width="15%" style="{$HeaderStyle}">
                            <xsl:value-of select="$ColumnHeader_UserName"/>
                        </th>
                        <th width="20%" style="{$HeaderStyle}">
                            <xsl:value-of select="$ColumnHeader_Time"/>
                        </th>
                        <th width="50%" style="{$HeaderStyle}">
                            <xsl:value-of select="$ColumnHeader_Operate"/>
                        </th>
                        <th width="15%" style="{$HeaderStyle}">
                            <xsl:value-of select="$ColumnHeader_Address"/>
                        </th>
                    </tr>
                </thead>
                
                <tbody style='vertical-align:top'>
                     <tr ><td colspan="4" height="5"></td></tr>  
                     <xsl:for-each select="log">
                     <xsl:sort order='ascending' select="user:xmlDateTime(string(opdate))" data-type="number"/>
                         
                       <tr height="23">
                        
                         <td valign="bottom"><xsl:value-of select="username"/></td>
                         <td valign="bottom" ><xsl:value-of select="opdate"/></td>
                         <td valign="bottom" ><xsl:value-of select="operate"/></td>
                         <td valign="bottom" ><xsl:value-of select="userip"/></td>  
                      </tr>
                      <tr bgcolor="#999999"><td colspan="4" height="1"></td></tr>  
                    </xsl:for-each>
                    
                    <tr><td colspan="4" align="right">合计:<xsl:value-of select="count(log)"/> 条 </td></tr>    
                </tbody>
            </table>
            </div>
        </body>
        </html>

    </xsl:template>
    </xsl:stylesheet>

    我生成的日志显示:
    <?xml version="1.0" encoding="gb2312"?>
    <?xml-stylesheet type='text/xsl' href='logInfo.xsl'?>
    <syslog><log><username>1/bf</username><operate>修改</operate><userip>192.168.0.232</userip><opdate>2006-3-16 9:34:49</opdate></log><log><username>1/bf</username><operate>修改</operate><userip>192.168.0.232</userip><opdate>2006-3-16 10:44:56</opdate></log><log><username>1/bf</username><operate>修改</operate><userip>192.168.0.232</userip><opdate>2006-3-16 10:45:13</opdate></log></syslog>

    怎样生成显示:
    <?xml version="1.0" encoding="gb2312"?>
    <?xml-stylesheet type='text/xsl' href='logInfo.xsl'?>
    <syslog>    
      <log>   
        <username>1/bf</username>   
        <operate>修改</operate>
        <userip>192.168.0.232</userip>
        <opdate>2006-3-17 9:34:27</opdate>
      </log>
      <log>   
        <username>1/bf</username>   
        <operate>修改</operate>
        <userip>192.168.0.232</userip>
        <opdate>2006-3-17 9:34:27</opdate>
      </log>
      <log>   
        <username>1/bf</username>   
        <operate>修改</operate>
        <userip>192.168.0.232</userip>
        <opdate>2006-3-17 9:34:27</opdate>
      </log>
    </syslog>
    这样看起来直观点
    哪位指点下,我很着急,谢谢了,我刚学XML


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/3/16 11:40:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XML源码及示例(仅原创和转载) 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/20 2:12:10

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    87.891ms