Connecting Tech Pros Worldwide Forums | Help | Site Map

xml parsing with php

erickrefener
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi,

I use PHP (and PHP socket functions) to exchange very short XML
documents between two Flash clients like this :
<MESSAGE id="myid" text="mytext" />
I don't parse the XML document within PHP but send back the XML document
made by the Flash client to another Flash client with a php socket and
Flash parse it with its own XML parser ...
In order to detect errors or non-XML data I do like this (in php):

switch (true){
case ( ereg("\<", trim($XMLdata)) ):
print 'xmldata';
break;
default:
print 'no xmldata';
}

(I must do this because Flash sends an empty "heartbeat" every 5
seconds, which is not XML data)


Now, I need to interpret my XML document inside php cause I want to make
php execute some commands when it receives a certain type of XML element.

XML data that can be sent from Flash :

<MESSAGE id="myid" text="mytext" /> or
<COMMAND1 /> or
<COMMAND2 /> or
or an empty string "" .

(in php) I can do :

switch (true){
case ( ereg("\<MESSAGE", trim($XMLdata)) ):
print 'xmldata is a txt message';
break;
case ( ereg("\<COMMAND1", trim($XMLdata)) ):
print 'xmldata is a command1';
break;
case ( ereg("\<COMMAND2", trim($XMLdata)) ):
print 'xmldata is a command2';
break;
default:
print 'no xmldata';
}

But what I'm wondering is whether it is the good way to proceed,
wouldn't it be faster to parse the xml document within php with Expat
library included when it receives a document "<COMMAND idcom="1" />" and
interpret "idcom" value instead of doing an "ereg("\<COMMAND1",
trim($XMLdata)) ?


many thanks,


Erick




Closed Thread