Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-16-2003, 07:29 AM   #1
LQ Newbie
Registered: Sep 2003
Location: australia
Posts: 8

Rep: Reputation: 0
XML php dom

How do u return a single node value from a xml documnet using php.

Javascript code for Windows server : WORKS OK
xmldoc = new ActiveXObject("Microsoft.XMLDOM");

xmldoc.async = false;


if(xmldoc.parseError.errorCode != 0){



nodes = xmldoc.documentElement.childNodes;

var maxl = xmldoc.documentElement.childNodes.length-1;

calc.namevalue.value = xmldoc.selectSingleNode("//VALUE").text;

PHP DOES NOT RETURN VALUE JUST THE WORD ARRAY IN THE TEXT BOX- my lack of understanding here is very low, can anyone assit in the proper syntax????

if(!$dom = domxml_open_file("../xml/data.xml")) {
echo "Error while parsing the document\n";
$root = $dom->document_element();
$xml_value = $root->get_elements_by_tagname("VALUE");
<title>Edit an XML Article</title>
<input name="name" type="text" id="name" value="<?php echo $xml_value ?>" size="30">
Old 09-16-2003, 07:49 AM   #2
LQ Newbie
Registered: Aug 2003
Posts: 13

Rep: Reputation: 0
I can't answer your question based on the XML commands you are using, but I can recommend use of I used it myself and it worked like a charm. And you are not limited to windows or some installed activex.

Simply include the phpxpath class and use it like this:

PHP Code:
require_once "../include/XPath.class.php";

$xpath = new XPath();

if( !
$xpath->importFromFile"somefile.xml" ) )

To retrieve a list of all matching elements call

PHP Code:
$List $xpath->match"/path/to/elements/allofthem/" );
$List as $One 
The value can be retrieved by:

PHP Code:

echo $xpath->getData"/family/dad/name" 
Old 09-20-2003, 07:04 AM   #3
LQ Newbie
Registered: Sep 2003
Location: australia
Posts: 8

Original Poster
Rep: Reputation: 0
thank you - seams nice however documentation is rather low -

can you point me to some examples ie reading in arrays::

require_once( "extras/XPath.class.php" );
$x = new XPath($file);
//$fut_exp_value = array();
$eyci_value = $x->getData("/TLEF/EYCI/VALUE");
$fut_exp1 = $x->getData("/TLEF/FUTURES/EXPIRE[1]");

<title>Edit an XML Article</title>
<input name="name" type="text" id="name" value="<?php echo $eyci_value ?>" size="30">

cant work out how to display array data from the xml document at all, EXPIRE is in the document 9 times, how do you read each one in????


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML in PHP Vort3x Linux - Software 1 12-20-2004 10:12 PM
CXOffice can't find XML::DOM BroX Slackware 0 10-25-2004 03:47 AM
php with DOM suport bm1 Linux - Software 0 05-17-2004 08:32 AM
how to recompile php to activate --with-dom phamtranquocvie Linux - Newbie 8 03-16-2004 01:17 PM
Php Vs. Xml zetsui Programming 4 02-18-2004 01:57 PM

All times are GMT -5. The time now is 09:55 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration