Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. $xml_file = new XMLWriter();
  2.  
  3. $xml_file->startElement("People");
  4.  
  5. while ($list_of_people->current != NULL ){
  6.  
  7. $xml_file->writeElement("Person"); // create a new person
  8.  
  9. $xml_file->startElement('Person');
  10.  
  11. $xml_file->writeAttribute('name', $list_of_people->current->name); // add their name as an attribute
  12.  
  13. if ($list_of_people->current->children != NULL){
  14.  
  15. while ($list_of_people->current->child_current != NULL){ // if they have children create them as well
  16.  
  17. $xml_file->writeElement("Person");
  18.  
  19. $list_of_people->startElement('Person');
  20.  
  21. $xml_file->writeAttribute('name', $list_of_people->current->child_current->child_name);
  22.  
  23. $xml_file->endElement();
  24.  
  25. $list_of_people->current->child_current = $list_of_people->current->child_current->next;
  26. }
  27. }
  28.  
  29. $xml_file->endElement();
  30.  
  31. $list_of_people->current = $list_of_people->current->next;
  32. }
  33.  
  34. <People>
  35. <Person name="Anna"></Person>
  36. <Person name="Joe">
  37. <Person name="Willy"></Person> // Joe has a child named Willy
  38. </Person>
  39. <Person name="Rob"></Person>
  40. </People>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement