XML Question

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

  1. Skeets

    Skeets Guest

    using php5 and given the code at the bottom of this post, this code
    works to print the expected value:

    foreach ($entry1 as $entry) {
    echo "Found {$entry->nodeValue}</br";
    }
    // prints "Found My List"

    however, this code does not work:

    echo "Found {$entry->nodeValue}</br";
    // prints "Found"

    how come?

    what can i do to isolate the element text value without the foreach
    loop? i've tried absolutely everying that i can think of without any
    good results.

    tia....

    ----code----

    $doc = new DOMDocument;
    $doc->preserveWhiteSpace = false;
    $doc->Load('default_conf/book.xml');
    $xpath = new DOMXPath($doc);
    $query1 = '//book/title';
    $entry1 = $xpath->query($query1);

    foreach ($entry1 as $entry) {
    echo "Found {$entry->nodeValue}</br";
    }
    Skeets, Feb 27, 2006
    #1
    1. Advertising

  2. Um, looks like '$entry1' is a list of xpath results.
    What does $entry1[0]->nodeValue give you?
    Crutcher Dunnavant, Feb 27, 2006
    #2
    1. Advertising

  3. Skeets

    Skeets Guest

    i get an error b/c some function can't run. i will try and post the
    specific error tomorrow.
    Skeets, Feb 28, 2006
    #3
  4. Skeets

    Harrie Guest

    Off-Topic Re: XML Question

    Skeets said the following on 2/27/2006 20:51 +0200:

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


    I don't have an answer to your question, but don't you miss a greater
    than sign at the end of the "br" element? And if this should be XHTML,
    shouldn't the slash be after "br", like so: <br />

    It's probably better to format your output with CSS than with (X)HTML's
    br element, but this is not the right newsgroup to discuss that.

    --
    Regards
    Harrie
    Harrie, Feb 28, 2006
    #4
  5. Skeets

    Skeets Guest

    actually, i don't get an error, i get a notice.

    code snippet:
    $entry1 = $xpath->query($query1);
    echo "Found {$entry1->nodeValue}";

    php notice:
    PHP Notice: Undefined property: DOMNodeList::$nodeValue in
    C:\web\html\dmt\_debug_tmp.php on line 26

    nothing is printed to the screen after "Found".

    anuy guidanc eor suggestions would be appreciated. i find the dearth
    of information regarding following a path and retrieving and element
    value bizarre - i would've thought this was the first thing someone
    would learn.
    Skeets, Feb 28, 2006
    #5
    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:
    431
    Bomb Diggy
    Jul 28, 2004
  2. Tony Prichard
    Replies:
    0
    Views:
    714
    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:
    464
    Patrick TJ McPhee
    Sep 15, 2004
  4. Andy
    Replies:
    0
    Views:
    524
  5. Erik Wasser
    Replies:
    5
    Views:
    428
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page