PDA

View Full Version : simplexml for PHP 4?


NancyJ
04-07-2006, 02:55 PM
Does anyone know of a class or library or anything that replicates the functionality of simpleXML for php 4?
I've looked at miniXML but it just seems to be overly complex in its implementation.
I'm really looking for something I can pass an XML string to and it will convert it into basic php objects - the miniXML seems to go a bit OTT with getAttribute() and getRoot and stuff, I just want to access the attributes ie $xml->attributes without having to 1) learn a completely new syntax, 2) rewrite existing code.

missing-score
04-08-2006, 02:15 AM
I don't know of anything but surely it wouldn't be too complex to create it yourself using the xml_parser functions? Are you working with a multi-namespace document (eg: something fairly complex) or a simple XML string?

NancyJ
04-08-2006, 09:10 AM
I guess it probably comes under the category of simple xml string but I've never created classless objects...
The data I get back looks like this:

<soap:envelope loads_of_xmlns_and_crap_here>
<soap:body>
<SearchResponse>
<SearchResult>
<Hotel>
<GeneralInfo>
<Details>
<Type>
<Text>

etc....
with simpleXML I can access the text using $xml->soapBody->SearchResponse->SearchResult->Hotel->GeneralInfo->Details->Text
Oviously I dump most of the structure into a single object... eg
(foreach $xml->soapBody->SearchResponse->SearchResult->Hotel as $hotel)
{
$text = $hotel->GeneralInfo->Detail->Text
}

The idea of trying to parse all the info into objects is quite daunting - I've never used the xml_parse functions (simple XML does everything I need to do) and the documentation on them looks sparse.

missing-score
04-08-2006, 12:00 PM
The xml_parser* functions were pretty much all that was available for PHP 4.

NancyJ
04-08-2006, 05:14 PM
The xml_parser* functions were pretty much all that was available for PHP 4.
How do I use them to get stuff into objects, theres really no documentation on the functions :(

missing-score
04-08-2006, 05:18 PM
you dont... Its not object based at all... You need to create your own callbacks to use for each encountered part of the XML file, eg: Start Tag, End tag, data, and so on.

http://www.php.net/xml gave me enough information to get using it, but I really hate it. I prefer using PHP 5 DOM (but I know you don't have that available).

NancyJ
04-08-2006, 07:19 PM
you dont... Its not object based at all...
Then its not what I want ;)
Looks like this is though http://www.ister.org/code/simplexml44/index.xhtml havent had a chance to try it yet but it seems to be pretty identical in syntax (apart from a little bit at the start but I can mod it) to simpleXML