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;

    $doc->Load('/book.xml');

    $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?

    tia...

    xml:

    <?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>
    <para>
    <informaltable>
    <tgroup cols="4">
    <thead>
    <row>
    <entry>Title</entry>
    <entry>Author</entry>
    <entry>Language</entry>
    <entry>ISBN</entry>
    </row>
    </thead>
    <tbody>
    <row>
    <entry>The Grapes of Wrath</entry>
    <entry>John Steinbeck</entry>
    <entry>en</entry>
    <entry>0140186409</entry>
    </row>
    <row>
    <entry>The Pearl</entry>
    <entry>John Steinbeck</entry>
    <entry>en</entry>
    <entry>014017737X</entry>
    </row>
    <row>
    <entry>Samarcande</entry>
    <entry>Amine Maalouf</entry>
    <entry>fr</entry>
    <entry>2253051209</entry>
    </row>
    <!-- TODO: I have a lot of remaining books to add.. -->
    </tbody>
    </tgroup>
    </informaltable>
    </para>
    </chapter>
    </book>
     
    Skeets, Feb 25, 2006
    #1
    1. Advertising

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.
Similar Threads
  1. Bomb Diggy
    Replies:
    0
    Views:
    456
    Bomb Diggy
    Jul 28, 2004
  2. Tony Prichard
    Replies:
    0
    Views:
    756
    Tony Prichard
    Dec 12, 2003
  3. Mark Van Orman

    embedding xml in xml as non-xml :)

    Mark Van Orman, Sep 14, 2004, in forum: XML
    Replies:
    5
    Views:
    487
    Patrick TJ McPhee
    Sep 15, 2004
  4. Andy
    Replies:
    0
    Views:
    550
  5. Erik Wasser
    Replies:
    5
    Views:
    484
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page