Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML Help

Thread Tools

XML Help

Posts: n/a
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"
"" [
<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.. -->

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Print XML parsing to JspWriter (out) Class org.xml.sax.helpers.NewInstance can not access a member of class javax.xml.parsers.SAXParser with modifiers "protected" Per Magnus L?vold Java 0 11-15-2004 02:27 PM
embedding xml in xml as non-xml :) Mark Van Orman XML 5 09-15-2004 05:57 AM
What XML technologies to learn first for "XML Processing" and "XML Mapping"? Bomb Diggy Java 0 07-28-2004 07:26 AM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM