Tuesday, September 7th, 2010

Get Information Using XPath in simpleXML

XPath is available in SimpleXML:

<?php
$s = simplexml_load_file('addresses.xml');
$emails = $s->xpath('/addresses/person/email');
 
foreach ($emails as $email) {
    // do something with $email
}
?>

Input XML:

<?xml version="1.0"?>
<addresses>
    <person>
        <name>Ramesh babu</name>
        <email>Ram@w3mauthor.com</email>
    </person>
    <person>
        <name>Jolld</name>
        <email>Jolld@w3mauthor</email>
    </person>
</addresses>
Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

Readers Comments (0)




Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.


Latest Additions

Popular User Submitted Links

1


Hosted & Optimized JS Libraries – Cached Commons

1


Multi-File Uploader & Resizer – Agile Uploader

1


Open source online notebook-to-do-list manager

1


3 tier app design in silverlight using azure & RIA services

1


Polymaps – A JS Library For Image & Vector-Tiled Maps

eXTReMe Tracker