Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Website Design/Showcase (http://www.chiefdelphi.com/forums/forumdisplay.php?f=64)
-   -   Listen-to xml parsing example thingie (http://www.chiefdelphi.com/forums/showthread.php?t=19577)

Trashed20 25-03-2003 23:28

Listen-to xml parsing example thingie
 
well, i got bored one day and tried some xml parsing based on some examples i found on the web for Listen-to. don't know if anyone is interested. Prolly not very efficient but hey. I basically just made it output an image (which you can already do) but you could do anything you want with the data. comments are good :)

PHP Code:

<?php
$file
"http://www.listen-to.com/xml.php/trashed20";
$depth = array();
$data1=array();


function 
startElement($parser$name$attrs) {
global 
$name;
    global 
$depth;
    for (
$i 0$i $depth[$parser]; $i++) {}
    
$depth[$parser]++;
}

function 
endElement($parser$name) {
    global 
$depth;
    
$depth[$parser]--;
}

function 
characterData($parser$data) {
global 
$data1;
if (
$data!="    "){$data1[] =$data;}}

$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");
if (!(
$fp fopen($file"r"))) {
    die(
"could not open XML input");
}

while (
$data fread($fp4096)) {
    if (!
xml_parse($xml_parser$datafeof($fp))) {
        die(
sprintf("XML error: %s at line %d",
                    
xml_error_string(xml_get_error_code($xml_parser)),
                    
xml_get_current_line_number($xml_parser)));
    }
}
xml_parser_free($xml_parser);

header ("Content-type: image/jpeg");
$im = @imagecreatefromjpeg ("temp2.jpg"); 
$tc  imagecolorallocate ($im255255255);
$time=date("m/d/y g:i a",$data1[11]);
$track=$data1[7];
$group=$data1[3];
imagestring ($im32307$timeblack);
imagestring ($im312631$groupblack);
imagestring ($im313652$trackblack);
imagejpeg ($im,"",85);
?>


Brandon Martus 26-03-2003 00:14

very cool.

gliebowitz 27-03-2003 00:44

I'm doing some client work now using "web services" (buzzword) and SOAP to integrate an inventory database with various platforms.

On my team's homepage, XML was used to dynamically feed info to the news system from a simple Access db (Flash and static pages) with ASP... not PHP. http://www.roboraiders.com

How long have you been working with PHP?

Trashed20 27-03-2003 07:07

i've been working with php since may of last year. I wrote our whole website ( http://www.lightningrobotics.com ) in php and using mysql. Making xml files to parse for every time someone wants to access your news is prolly pretty hard on your system. Doesn't ASP have dirrect connections to access db's?

I chose php as it is c++ structured and syled which i like :)

gliebowitz 27-03-2003 15:13

Cool


A connection is made to an Access db just like you would do for any other ODBC connection. The server we're using is a 1.4 Ghz P3 Dell, so it doesn't seem to get bogged down too often ;-).

If you are interested, this is the code to the asp script requested by the Flash intro to get the latest news:

PHP Code:

var months = new Array ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
var 
monthValue = new Array (13,14,15,16,17,18,19,20,21,22,23,24);
var 
now = new Date();
var 
month now.getMonth();
var 
date now.getDate();
var 
day now.getDay();
var 
year now.getYear();
var 
week 1;
if (
year 2000year year 1900;
var 
monarr = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
if (((
year == 0) && (year 100 != 0)) || (year 400 == 0)) monarr[1] = 29;
sday day;
while (
date != 0){
date --;
sday --;
    if (
sday 0){
        
sday sday 7;
        
week ++;
    }
}
var 
currentMonth months[month]
var 
currentWeek week
var current_category monthValue[month]
var 
out
sql 
"SELECT * FROM data where data_category = " current_category " order by data_subcategory, data_name";
rs Server.CreateObject("ADODB.RecordSet");
rs.Open (sqlConn2,3);
if (
rs.EOF){     // check to see if rs is empty
out += ('    <button name="No articles">\n')
out += ('        <info>There are no new events for this week.</info>\n')
out += ('    </button>\n')
}
else{            
// rs not empty

    
temp_subcat""//this string used to group records by subcategory
    
fields = new Object(); // this object used to store fields in records

while (! (rs.EOF)){

    
// clean up data and put it into the fields object:
    
for ( field_number 0field_number rs.fields.count field_number++ )
        {
        
temp_field String(rs.fields(field_number).Name);
        
temp_content String(rs.fields.item(temp_field));
        
temp_content temp_content.replace(/&#039;/g,"'");
        
if (temp_field.search(/date/) > )     // check for date fields
            
{temp_content slash_date(temp_content);} 
        else if (
temp_content == "null") {temp_content ""; }
        
fields[temp_field] = temp_content
        
// end looping through fields in current record

        // subcategories: when we get to a new one, display it
        
if (temp_subcat != fields.data_subcategory){
            
temp_subcat fields.data_subcategory;
        }
if (
temp_subcat == currentWeek){
            
out += ('   <data>\n')
            
out += ('    <name>'+fields.data_name+'</name>\n')
            
out += ('    <info>'+fields.data_url+'</info>\n')
            
out += ('    <id>'+fields.data_uid+'</id>\n')
            
out += ('   </data>\n')
        } else {
}

        
rs.move(1);
        } 
// end while recordset
     // end else (rs not empty)
rs.Close ();
}
if (
out==""){
            
out += ('   <data>\n')
            
out += ('    <name>No articles.</name>\n')
            
out += ('    <info>There are no new events for this week.</info>\n')
            
out += ('    <id>undefined</id>\n')
            
out += ('   </data>\n')
}
Response.Write(out)
Conn.Close (); 



All times are GMT -5. The time now is 01:53.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi