|
#1
|
|||
|
|||
|
Hi guys!!!
I need some examples or an explanation for read some data of a XML file and for write some elements in the file with a form everything with PHP. Can You help me?? Thanks!!! |
|
#2
|
|||
|
|||
|
The server that I want to put my page support PERL 5.8.7 and PHP 4.4.2.. What's the better language the read/write of/on a XML script without a DB in your opinion?? Can I choose one of them??
|
|
#3
|
||||
|
||||
|
Reading an XML File using PHP
HTML Code:
XML Code: file name - employees.xml <?xml version="1.0" encoding="iso-8859-1"?> <employees> <employee> <name>Mark</name> <age>27</age> <salary>$5000</salary> </employee> <employee> <name>Jack</name> <age>25</age> <salary>$4000</salary> </employee> </employees> PHP Code:
Writing XML using PHP PHP Code:
As i don't know much about perl it is not wise to comment about that. I think PHP is enough for this purpose. |
|
#4
|
|||
|
|||
|
But this solution works with PHP 4? or just for PHP 5?
|
|
#5
|
||||
|
||||
|
hmmmm i've developed it with PHP 5 i don't have PHP4 could you please test that it in your machine?
|
|
#6
|
||||
|
||||
|
Heres my conversion...
<?php $doc = new DOMDocument(); $doc->load( 'info.xml' ); $blog = $doc->getElementsByTagName( "post" ); foreach( $blog as $post ) { $headers = $post->getElementsByTagName( "header" ); $header = $headers->item(0)->nodeValue; $dates= $post->getElementsByTagName( "date" ); $date= $dates->item(0)->nodeValue; $notes = $post->getElementsByTagName( "note" ); $note = $notes->item(0)->nodeValue; $links = $post->getElementsByTagName( "link" ); $link = $links->item(0)->nodeValue; echo ' <div class="blog">$header</div> <div class="small">$date</div> <div class="note">$note</div> <a href="$link">$link</a> '; } ?> XML doc... <blog> <post> <header></header> <date></date> <note></note> <link></link> </post> </blog> |
|
#7
|
|||
|
|||
|
i create the exact xml and php files that you've written there, but when i test them on my site, i get an error like this
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /homepages/1/d206546483/htdocs/jussieutik/test/tres.php on line 15 my php is like this, is this the problem?? Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<?php
$doc = new DOMDocument();
$doc->load( 'employees.xml' );
$employees = $doc->getElementsByTagName( "employee" );
foreach( $employees as $employee )
{
$names = $employee->getElementsByTagName( "name" );
$name = $names->item(0)->nodeValue;
$ages= $employee->getElementsByTagName( "age" );
$age= $ages->item(0)->nodeValue;
$salaries = $employee->getElementsByTagName( "salary" );
$salary = $salaries->item(0)->nodeValue;
echo "<b>$name - $age - $salary\n</b><br>";
}
?>
<body>
</body>
</html>
|
|
#8
|
|||
|
|||
|
I've been trying to get a php class to write into xml... I've looked around and all the code seems the same to the below and everyone i have tried is coming up with the same error msg..
Warning: domdocument() expects at least 1 parameter, 0Has anyone else had this problem? Does anyone know of an answer? Thanks Quote:
|
|
#9
|
||||
|
||||
|
Also, note this other current thread--
http://www.dynamicdrive.com/forums/s...ad.php?t=24776
__________________
Daniel - Freelance Web Design | <?php?> | <html>| Ich kann Deutsch. | Capisco l'italiano. | Estudio español. | Estudava português. | un peu de français | 日本語の学生です。| درست العربية |
|
#10
|
|||
|
|||
|
i try to write a xml file but i have error with :
"Warning: domdocument::domdocument() expects at least 1 parameter, 0 given in C:\xampp\htdocs\demo_ghifilexml\ghifilexml.php on line 2 Fatal error: Call to undefined method domdocument::load() in C:\xampp\htdocs\demo_ghifilexml\ghifilexml.php on line 3 " i copy your code and paste in my php text so i understand what happen. my php version:5.2.6 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
|
|