PHP what is the best approach to using XML? Need to create and parse XML responses
What are the recommended libraries for XML in PHP? Advantages开发者_高级运维? Looking to create/send/parse XML. Needs to support High Volume (Millions of calls per day)
PHP supports a number of XML libraries.
If memory is an issue, for instance due to large files, use an Event-based parser over a tree-based one.Tree-based parsers must fully load the file into memory in order to parse the XML. Event-based parsers do not need to load the entire file into memory to begin parsing.
See this article about what's new with XML in PHP5 and a discussion of their pros and cons.
You might also reconsider where you store the data, since filesystem might be too slow for millions of calls. How about Xindice?
SimpleXml is by far the easiest! For any of the missing features in SimpleXml you can try bXml, a warper library I wrote.
If you want use PHP intern XML Parser there are
XPATH DOM SimpleXml
Or If you want to use a XML Parser for PHP i can recommend Simplepie
there are a lot but Simplepie is one of the Best.
Here is a Simple overview of how you could use it.
<?php
require_once('simplepie.inc');
$feed = new SimplePie();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
$feed->init();
$feed->handle_content_type();
?>
<h1><a href="<?php echo $feed->get_permalink(); ?>">
<?php echo $feed->get_title(); ?></a></h1>
<p><?php echo $feed->get_description(); ?></p>
<?php foreach ($feed->get_items(0, 5) as $item): ?>
<h2 class="title"><a href="<?php echo $item->get_permalink(); ?>">
<?php echo $item->get_title(); ?></a></h2>
<?php echo $item->get_description(); ?>
<p>
<small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?>
</small></p>
<?php endforeach; ?>
精彩评论