XML Question

S

Skeets

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";
}
 
C

Crutcher Dunnavant

Um, looks like '$entry1' is a list of xpath results.
What does $entry1[0]->nodeValue give you?
 
S

Skeets

i get an error b/c some function can't run. i will try and post the
specific error tomorrow.
 
H

Harrie

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.
 
S

Skeets

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,255
Members
46,853
Latest member
GeorgiaSta

Latest Threads

Top