Raised This Month: $ Target: $400
 0% 

Read XML files


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
miki208
Junior Member
Join Date: Aug 2011
Old 04-20-2012 , 13:28   Read XML files
Reply With Quote #1

Is this possible?
Please, help me, I need it...
miki208 is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 04-20-2012 , 14:08   Re: Read XML files
Reply With Quote #2

If you want to read a file, with XML extension, it's possible. It's also possible to read a file with OINFNDW extension if you want.

PHP Code:
new iFile fopen"MyFile.MyExtension""r" ), iReadRowscMyRow256 ][ 32 ];
while( !
feofiFile ) ) fgetsiFilecMyRowiReadRows ], 31 ), iReadRows++;
fcloseiFile ); 
Be careful, a file which not exists and it's opened will crash server.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-21-2012 , 00:57   Re: Read XML files
Reply With Quote #3

You can read any plain text file (or even binary files if you know what you are doing) but there is nothing that is default that will actually parse a xml content. Look in the Code Snippets/Tutorials to see if it's been done. Also, search in the Scripting Help forum. If you can't find it then it's likely that you will have to create it. However, I don't expect that it would be an easy task unless you are only looking for a single value and you don't want all the information in the file.

Quote:
Originally Posted by claudiuhks View Post
Be careful, a file which not exists and it's opened will crash server.
Or better yet, you should put the check in the code.
__________________
fysiks is offline
miki208
Junior Member
Join Date: Aug 2011
Old 04-21-2012 , 11:27   Re: Read XML files
Reply With Quote #4

But if I want to parse it with PHP script, how to send request to this PHP script and get returned data from PHP?
Someone tell me that is possible with socket, but I don't know how, please write me an example how to send request and get data. :/
miki208 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-21-2012 , 13:10   Re: Read XML files
Reply With Quote #5

You have to use sockets to send/receive info from a webpage (your php script). There are many examples of this because it's a popular request. Also, check in the tutorials forum and see if there is a sockets tutorial.
__________________
fysiks is offline
miki208
Junior Member
Join Date: Aug 2011
Old 04-22-2012 , 06:24   Re: Read XML files
Reply With Quote #6

socket_open ( hostname[], port, protocol, &error )
Can u write me an example, how to connect, if my php file is here: www.somesite.com/myfile.php
Which arguments will be in this functon if I want to use socket with this php file?
Sry for bad english :/
EDIT: this site and php file doesn't exists, i want code for connecting socket with this file, based on this example...

Last edited by miki208; 04-22-2012 at 06:26.
miki208 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-22-2012 , 14:26   Re: Read XML files
Reply With Quote #7

Look at examples.
__________________
fysiks is offline
miki208
Junior Member
Join Date: Aug 2011
Old 04-22-2012 , 14:58   Re: Read XML files
Reply With Quote #8

PHP Code:
#include <amxmodx> 
#include <sockets> 

#define PLUGIN    "sdfds" 
#define AUTHOR    "fsdsddfs" 
#define VERSION    "1.0" 

// Tasks 
#define TASKID_GETANSWER            0 
#define TASKID_CLOSECONNECTION        1 


new g_Socket 

// Data buffer 
new g_Data[1000
public 
plugin_init() 

    
register_plugin(PLUGINVERSIONAUTHOR


public 
plugin_cfg() 

    
// Connect 
    
new errorsendbuffer[512
    
g_Socket socket_open("mikisoft.clanteam.com"80SOCKET_TCPerror
  
     
    
// Send page request 
    
format(sendbuffer511"GET /prognoza.php HTTP/1.1^nHost:mikisoft.clanteam.com^r^n^r^n"
    
socket_send(g_Socketsendbuffer511
     
     
    
// Setting the tasks for handeling the response 
    
set_task(1.0"task_waitanswer"TASKID_GETANSWER""0"a"15
    
set_task(16.0"task_closeconnection"TASKID_CLOSECONNECTION""0""0
}

public 
task_waitanswer(id

    
// It changed? 
    
if (socket_change(g_Socket)) 
    { 
        
// Get the data 
        
socket_recv(g_Socketg_Data999)  
        
socket_close(g_Socket
             
            
// Remove the tasks 
            
remove_task(TASKID_GETANSWER
            
remove_task(TASKID_CLOSECONNECTION
        
client_print(id,print_chat,g_Data)
    } 


public 
task_closeconnection(id

    
// Close connection if no response in 16 seconds. 
    
socket_close(g_Socket

this doesn't work. :/
I must to get answer from server: 'pozzz' :/
I get this answer:
PHP Code:


HTTP
/1.1 200 OK
Date
Sun22 Apr 2012 19:13:39 GMT
Server
Apache
X
-Powered-ByPHP/5.2.17
Content
-Length:
6
Connection

PHP script 'prognoza.php':
PHP Code:
<?php
    
echo "pozzzz";
?>

Last edited by miki208; 04-22-2012 at 15:14.
miki208 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-24-2012 , 10:36   Re: Read XML files
Reply With Quote #9

PHP Code:
public task_waitanswer(id

    
// It changed? 
    
if (socket_change(g_Socket)) 
    { 
        
// Get the data 
        
socket_recv(g_Socketg_Data999)  
        
socket_close(g_Socket
        
        
// Remove the header from the data
        
new pos contain(g_Data"^r^n^r^n")
        if(
pos 0) {
                
format(g_Data999g_Data[pos 2])
        }
             
            
// Remove the tasks 
            
remove_task(TASKID_GETANSWER
            
remove_task(TASKID_CLOSECONNECTION
        
client_print(id,print_chat,g_Data)
    } 

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 04-24-2012 at 10:36.
Exolent[jNr] is offline
miki208
Junior Member
Join Date: Aug 2011
Old 04-25-2012 , 18:20   Re: Read XML files
Reply With Quote #10

Tnx you man
I made plugin 'weather'. When u type /weather city_name, socket must to connect and send data to php script and get answer. That's work. I tested my plugin on server which is hosted on my computer. And that's work only when i type /weather city, but other players can't. Is it possible that sockets only can to connect from my computer, only from IP adress of my server, and how to resolve this problem? :/
PHP Code:
//plugin_init
register_concmd("say","s",0,"plugin");
//s function is called when someone activate say command, and check is it starts with '/weather', and connect socket
//i note that only I can to can to call this function, but i want to all players can
public s(id

    
// Connect 
    
new DATA[1000];
    new 
komanda[50];
    
read_argv(id,komanda,sizeof(komanda));
    new 
naredba[50];
    
strtok(komanda,naredba,49,argument,49,' ');
    
replace_all(argument,49," ","%20");
    if(
contain(komanda,"/weather")==0)
    {
    new 
errorsendbuffer[512
    
g_Socket socket_open("serbia-chat.net16.net"80SOCKET_TCPerror
  
     
    
// Send page request 
    
format(sendbuffer511"GET /prognoza.php?grad=%s HTTP/1.1^nHost:serbia-chat.net16.net^r^n^r^n",argument
    
socket_send(g_Socketsendbuffer511
     
     
    
// Setting the tasks for handeling the response 
    
set_task(1.0"task_waitanswer"TASKID_GETANSWER""0"a"15
    
set_task(16.0"task_closeconnection"TASKID_CLOSECONNECTION""0""0
   }
   

miki208 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:41.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode