Jump to content

need help "xmlCreateFile"


sckatchof

Recommended Posts

hello guys ,

why this script don't work ?

local xmlFile = nil 
local xmlNode = nil 
local yearday, hour 
  
function openFile( ) 
    local time = getRealTime( ) 
    yearday = time.yearday 
    hour = time.hour 
    local fileName = ( "TNSlogs/%04d-%02d-%02d/%02d.html" ):format( time.year + 1900, time.month + 1, time.monthday, time.hour ) 
      xmlFile = xmlLoadFile( fileName ) 
       if not xmlFile then 
        xmlFile = xmlCreateFile( fileName, "html" ) 
        local head = xmlCreateChild( xmlFile, "head" ) 
        local title = xmlCreateChild( head, "title" ) 
        xmlNodeSetValue( title, ( "TNS MTA :: Client Logs :: %04d-%02d-%02d" ):format( time.year + 1900, time.month + 1, time.monthday ) ) 
         
        local style = xmlCreateChild( head, "style" ) 
        xmlNodeSetAttribute( style, "type", "text/css" ) 
        xmlNodeSetValue( style, "body { font-family: Tahoma; font-size: 0.8em; background: #000000; }  p { padding: 0; margin: 0; } .v1 { color: #AAAAAA; } .v2 { color: #DDDDDD; } .v3 { white-space:pre; }" ) 
         
        xmlNode = xmlCreateChild( xmlFile, "body" ) 
        xmlSaveFile( xmlFile ) 
    else 
        xmlNode = xmlFindChild( xmlFile, "body", 0 ) 
    end 
end 
  
addEventHandler( "onClientResourceStart", getResourceRootElement( ), 
    function( ) 
        openFile( ) 
    end 
) 

Link to comment

here's how the html file would look after the script runs:

>    >        >"TNS MTA :: Client Logs :: 2012-11-7">        ="text/css">body{            font-family: Tahoma;            font-size: 0.8em;            background: #000000;        }        p{            padding: 0;            margin: 0;        }        .v1{            color: #AAAAAA;        }        .v2{            color: #DDDDDD;        }        .v3{            white-space:pre;        }        >    >    >    >>

try this:

local xmlFile = nil 
local xmlNode = nil 
local yearday, hour 
  
  
local time = getRealTime( ) 
yearday = time.yearday 
hour = time.hour 
local fileName = ( "TNSlogs/%04d-%02d-%02d/%02d.html" ):format( time.year + 1900, time.month + 1, time.monthday, hour )--already defined hour as year.hour 
xmlFile = xmlLoadFile( fileName ) 
if not xmlFile then 
    xmlFile = xmlCreateFile( fileName, "html" ) 
    local head = xmlCreateChild( xmlFile, "head" ) 
    local title = xmlCreateChild( head, "title" ) 
        xmlNodeSetValue( title, ( "TNS MTA :: Client Logs :: %04d-%02d-%02d" ):format( time.year + 1900, time.month + 1, time.monthday ) ) 
    local style = xmlCreateChild( head, "style" ) 
        xmlNodeSetAttribute( style, "type", "text/css" ) 
        xmlNodeSetValue( style, "body { font-family: Tahoma; font-size: 0.8em; background: #000000; }  p { padding: 0; margin: 0; } .v1 { color: #AAAAAA; } .v2 { color: #DDDDDD; } .v3 { white-space:pre; }" ) 
        
    xmlNode = xmlCreateChild( xmlFile, "body" ) 
    xmlSaveFile( xmlFile ) 
else 
    xmlNode = xmlFindChild( xmlFile, "body", 0 ) 
end 

What exactly doesn't work?

He's trying to make a webpage using xml.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...