我有一個對象,其中包含來自導出的OLAT備份的數據(OLAT是用Java編寫的電子學習工具)。使用一個對象來創建文件夾結構
現在我需要製作另一種類型的備份文件,即Moodle備份文件,以便我可以將它導入Moodle本身(另一個用PHP編寫的電子學習工具)。所以我的計劃是創建Moodle備份所需的文件夾結構,並將數據寫入相應的.xmls和路徑。
我知道這聽起來很模糊,但我的問題是這樣的:創建這些文件的最佳方法是什麼?例如,我需要一個.xml這種結構:
<?xml version="1.0" encoding="UTF-8"?>
<course id="8" contextid="78">
<shortname>Test Course Short</shortname>
<fullname>Test Course Long</fullname>
<idnumber></idnumber>
<summary></summary>
<summaryformat>1</summaryformat>
<format>topics</format>
<showgrades>1</showgrades>
<newsitems>5</newsitems>
<startdate>1394668800</startdate>
<marker>0</marker>
<maxbytes>0</maxbytes>
<legacyfiles>0</legacyfiles>
<showreports>0</showreports>
<visible>1</visible>
<groupmode>0</groupmode>
<groupmodeforce>0</groupmodeforce>
<defaultgroupingid>0</defaultgroupingid>
<lang></lang>
<theme></theme>
<timecreated>1394632991</timecreated>
<timemodified>1394632991</timemodified>
<requested>0</requested>
<enablecompletion>0</enablecompletion>
<completionnotify>0</completionnotify>
<numsections>8</numsections>
<hiddensections>0</hiddensections>
<coursedisplay>0</coursedisplay>
<category id="1">
<name>Miscellaneous</name>
<description>[email protected]@$</description>
</category>
<tags>
</tags>
</course>
我知道這聽起來像基本的PHP,但是這也幾乎是它是什麼。我如何使用PHP創建這個文件?
隨着simpleXML http://php.net/manual/en/book.simplexml.php。它是許多php xml庫之一 – aleation
一個簡單的模板引擎(ie.e.tigig)也可能是有用的。 –