How to parse an xml

250 views
Skip to first unread message

prasath nadarajah

unread,
Mar 27, 2012, 12:01:29 AM3/27/12
to joomla-de...@googlegroups.com
What is the best way to parse and xml file returned from an http request?
Should i use php simplexml element?

--
Cheers
Prasath Nadarajah

David Swain

unread,
Mar 27, 2012, 5:45:23 AM3/27/12
to joomla-de...@googlegroups.com
When parsing install manifests (just an xml file), the installation script ( libraries/joomla/installer/installer.php ) does:

J 1.5:
JFactory::getXMLParser('Simple')
the 1.5 one invokes a "JSimpleXML" which appears to be a re-creation of simplexml which didn't exist in php 4.* (which J1.5 supports).

J 2.5:
$xml = JFactory::getXML($file)
This in turn creates a simplexml object for all the caller's xml needs

I'd suggest using the same methods as the Joomla core. Failing that just going to simplexml seems reasonable.

:-Dave

Amy Stephen

unread,
Mar 27, 2012, 5:09:53 PM3/27/12
to joomla-de...@googlegroups.com
For what it's worth, I just use PHP's SimpleXML

Louis Landry

unread,
Mar 27, 2012, 6:20:36 PM3/27/12
to joomla-de...@googlegroups.com
There are several techniques to parsing XML regardless of where it comes from.  While SimpleXML is nice, it (like DOM parsing) can be quite memory intensive if you are processing large XML files.  I've found that if I'm handling XML files that are very large (or have the potential to be very large) that a great tradeoff is to use XMLReader to stream through bite sized sections of the XML and convert those sections to SimpleXML elements for easy handling.  Ultimately your mileage will vary depending on use case, but the tools available in PHP natively are really good.

- Louis
Reply all
Reply to author
Forward
0 new messages