Get information from form and write to xml file using php?

I want to get information from a form and write to an xml file using php? My XML file is in a tree structure

Example of my xml file:

<BookStore>
    <Book>
        <name>TODO</name>
        <url>TODO</url>
    </Book>
</BookStore>

      

when i submit it xml will be generated but i want Book

and BookStore

also as parent. I created before name

and url

. But I do not know how to create Book

and BookStore

too?

+3


source to share


1 answer


You just need to create new parent elements and then add children.



$bookstore = $doc->createElement('Bookstore');
$book = $doc->createElement("Book");

/* your code */

/* append name and url to $book */
$book->appendChild($textareaNode);
$book->appendChild($textareaNode1); 
$bookstore->appendChild($book);
$doc->appendChild($bookstore);

$doc->save("d.xml");

      

0


source







All Articles