XML Help

Discussion in 'XML' started by Skeets, Feb 25, 2006.

  1. Skeets

    Skeets Guest

    hi all, the following code works perfect (the xml is loacted at the
    bottom of this post):

    $doc = new DOMDocument;

    // We don't want to bother with white spaces
    $doc->preserveWhiteSpace = false;


    $xpath = new DOMXPath($doc);

    $query1 = '//book/title';

    $entry1 = $xpath->query($query1);

    foreach ($entry1 as $entry) {
    echo "Found {$entry->nodeValue}," .
    " by {$entry->nodeValue}<br />";

    however, i don't know how to get a single value.

    echo "Found {$entry1->nodeValue};

    echo "Found {$entry1[0]->nodeValue};

    don't work

    i'm trying to use XPath and XML to nail down the value in the
    book/title path ("My lists")

    what am i doing worng?



    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
    <book id="listing">
    <title>My lists</title>
    <chapter id="books">
    <title>My books</title>
    <tgroup cols="4">
    <entry>The Grapes of Wrath</entry>
    <entry>John Steinbeck</entry>
    <entry>The Pearl</entry>
    <entry>John Steinbeck</entry>
    <entry>Amine Maalouf</entry>
    <!-- TODO: I have a lot of remaining books to add.. -->
    Skeets, Feb 25, 2006
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.