Get Information Using XPath in DOM

<?php
$dom = new DOMDocument;
$dom->load('addresses.xml');
$xpath = new DOMXPath($dom);
$email = $xpath->query('/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

Filed Under: PHP XML Examples

RSSComments (0)

Trackback URL

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.