petit probleme pour charger mon doc xml

petit probleme pour charger mon doc xml - Programmation

Marsh Posté le 21-08-2002 à 10:14:57    

voila g regarder le tuito sur l'utilisation du XML dans PHP (http://www.phpbuilder.com/columns/matt20001228.php3)
mais j'ai des pb avec php y'a as de messsage d'erreur mais en sortie j'ai :  
the , employee
the , employee
the , employee
 
sinon voila le code php :

Code :
  1. <?php
  2. # iterate through an array of nodes
  3. # looking for a text node
  4. # return its content
  5. function get_content($parent)
  6. {
  7.     $nodes = $parent->children();
  8.     while($node = array_shift($nodes))
  9.         if ($node->type == XML_TEXT_NODE)
  10.             return $node->content;
  11.     return "";
  12. }
  13. # get the content of a particular node
  14. function find_content($parent,$name)
  15. {
  16.     $nodes = $parent->children();
  17.     while($node = array_shift($nodes))
  18.         if ($node->name == $name)
  19.             return get_content($node);
  20.     return "";
  21. }
  22. # get an attribute from a particular node
  23. function find_attr($parent,$name,$attr)
  24. {
  25.     $nodes = $parent->children();
  26.     while($node = array_shift($nodes))
  27.         if ($node->name == $name)
  28.             return $node->getattr($attr);
  29.     return "";
  30. }
  31. # load xml doc
  32. $doc = xmldocfile('c:\employ.xml') or die ("erreur ne trouve pas le fichier" );
  33. # get root Node (employees)
  34. $root = $doc->root();
  35. # get an array of employees' children
  36. # that is each employee node
  37. $employees = $root->children();
  38. # shift through the array
  39. # and print out some employee data
  40. while($employee = array_shift($employees))
  41. {
  42.     if ($employee->type == XML_TEXT_NODE)
  43.         continue;
  44.     $name = find_content($employee,"name" );
  45.     $pos = find_content($employee,"position" );
  46.     $type = find_attr($employee,"position","type" );
  47.     echo $name." the ".$pos.", ".$type." employee<br>";
  48. }
  49. ?>


 
et le xml  

Code :
  1. <?xml version="1.0"?>
  2. <employees company="zoomedia.com">
  3. <employee>
  4.  <name>Matt</name>
  5.  <position type="contract">Web Guy</position>
  6. </employee>
  7. <employee>
  8.  <name>George</name>
  9.  <position type="full time">Mad Hacker</position>
  10. </employee>
  11. <employee>
  12.  <name>Wookie</name>
  13.  <position type="part time">Hairy SysAdmin</position>
  14. </employee>
  15. </employees>


 
qq'un aurait une idee

Reply

Marsh Posté le 21-08-2002 à 10:14:57   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed