Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $xml_file = new XMLWriter();
- $xml_file->startElement("People");
- while ($list_of_people->current != NULL ){
- $xml_file->writeElement("Person"); // create a new person
- $xml_file->startElement('Person');
- $xml_file->writeAttribute('name', $list_of_people->current->name); // add their name as an attribute
- if ($list_of_people->current->children != NULL){
- while ($list_of_people->current->child_current != NULL){ // if they have children create them as well
- $xml_file->writeElement("Person");
- $list_of_people->startElement('Person');
- $xml_file->writeAttribute('name', $list_of_people->current->child_current->child_name);
- $xml_file->endElement();
- $list_of_people->current->child_current = $list_of_people->current->child_current->next;
- }
- }
- $xml_file->endElement();
- $list_of_people->current = $list_of_people->current->next;
- }
- <People>
- <Person name="Anna"></Person>
- <Person name="Joe">
- <Person name="Willy"></Person> // Joe has a child named Willy
- </Person>
- <Person name="Rob"></Person>
- </People>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement