LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 09-16-2003, 06:29 AM   #1
amirspl
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;

xmldoc.load("../xml/data.xml");

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

window.location.replace("../error.shtml");}

else{

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

<?php
session_start();
if(!$dom = domxml_open_file("../xml/data.xml")) {
echo "Error while parsing the document\n";
exit;
}
$root = $dom->document_element();
$xml_value = $root->get_elements_by_tagname("VALUE");
?>
<html>
<title>Edit an XML Article</title>
<body>
<input name="name" type="text" id="name" value="<?php echo $xml_value ?>" size="30">
</body>
</html>
 
Old 09-16-2003, 06:49 AM   #2
bwMarkus
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 http://sourceforge.net/projects/phpxpath/. 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" ) )
{
   die();

To retrieve a list of all matching elements call

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

PHP Code:

echo $xpath->getData"/family/dad/name" 
HTH
 
Old 09-20-2003, 06:04 AM   #3
amirspl
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::

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

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

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


Reply



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 09:12 PM
CXOffice can't find XML::DOM BroX Slackware 0 10-25-2004 02:47 AM
php with DOM suport bm1 Linux - Software 0 05-17-2004 07:32 AM
how to recompile php to activate --with-dom phamtranquocvie Linux - Newbie 8 03-16-2004 12:17 PM
Php Vs. Xml zetsui Programming 4 02-18-2004 12:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:15 PM.

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