简体   繁体   English

从表单获取信息并使用php写入xml文件?

[英]Get information from a form and writing to an xml file using php?

I want to get information from a form and writing to an xml file by using php ? 我想从表单中获取信息并使用php写入xml文件? My xml file is in tree structure 我的xml文件是树形结构

Example of my xml file: 我的xml文件示例:

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

when I submit it will create a xml but I want Book and BookStore also as a parent. 当我提交它会创建一个xml但我想要BookBookStore也作为父。 I created till name and url . 我创建了直到nameurl But I dont know how to create Book and BookStore too? 但我也不知道如何创建BookBookStore

You just need to create new parent elements and then append the child. 您只需要创建新的父元素,然后附加子元素。

$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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM