From: sam wych (s_wych@yahoo.fr)
Date: 21/08/2002 - 08:28
voila j'ai regarder le tuto sur l'utilisation du XML
dans PHP
(http://www.phpbuilder.com/columns/matt20001228.php3)
mais j'ai des pb avec php y'a pas de messsage d'erreur
mais en sortie j'ai :
the , employee
the , employee
the , employee
sinon voila le code php :
Code :
<?php
# iterate through an array of nodes
# looking for a text node
# return its content
function get_content($parent)
{
$nodes = $parent->children();
while($node = array_shift($nodes))
if ($node->type == XML_TEXT_NODE)
return $node->content;
return "";
}
# get the content of a particular node
function find_content($parent,$name)
{
$nodes = $parent->children();
while($node = array_shift($nodes))
if ($node->name == $name)
return get_content($node);
return "";
}
# get an attribute from a particular node
function find_attr($parent,$name,$attr)
{
$nodes = $parent->children();
while($node = array_shift($nodes))
if ($node->name == $name)
return $node->getattr($attr);
return "";
}
# load xml doc
$doc = xmldocfile('c:\employ.xml') or die ("erreur
ne trouve pas le fichier");
# get root Node (employees)
$root = $doc->root();
# get an array of employees' children
# that is each employee node
$employees = $root->children();
# shift through the array
# and print out some employee data
while($employee = array_shift($employees))
{
if ($employee->type == XML_TEXT_NODE)
continue;
$name = find_content($employee,"name");
$pos = find_content($employee,"position");
$type =
find_attr($employee,"position","type");
echo $name." the ".$pos.", ".$type."
employee<br>";
}
?>
et le xml
Code :
<?xml version="1.0"?>
<employees company="zoomedia.com">
<employee>
<name>Matt</name>
<position type="contract">Web Guy</position>
</employee>
<employee>
<name>George</name>
<position type="full time">Mad Hacker</position>
</employee>
<employee>
<name>Wookie</name>
<position type="part time">Hairy
SysAdmin</position>
</employee>
</employees>
qq'un aurait une idee ??
___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com
--
Devenez redacteur <XML>fr et contribuez au developpement du
xml francophone (http://xmlfr.org/infos/redacteurs/) !
Liste de diffusion "xml-tech@xmlfr.org" (http://xmlfr.org).
Cette liste est a votre disposition pour discuter en francais de
tout sujet technique lie a XML.
Pour resilier votre abonnement, envoyez un message contenant
la commande "unsubscribe" a xml-tech-request@xmlfr.org
(mailto:xml-tech-request@xmlfr.org?Subject=unsubscribe)
Archive générée par hypermail 2.1.3 le 28/06/2004 - 11:06 UTC
webmaster@xmlfr.org
|