【发布时间】:2014-03-14 08:44:56
【问题描述】:
我有一个对象,其中包含来自导出的 OLAT 备份的数据(OLAT 是用 Java 编写的电子学习工具)。
现在我需要制作另一种“类型”的备份文件,即 Moodle 备份文件,以便我可以将其导入 Moodle 本身(另一种用 PHP 编写的电子学习工具)。所以我的计划是创建 Moodle 备份所需的文件夹结构,并将数据写入相应的 .xmls 和路径。
我知道这听起来很模糊,但我的问题是:创建这些文件的最佳做法是什么?例如,我需要制作一个具有这种结构的 .xml: p>
<?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>$@NULL@$</description>
</category>
<tags>
</tags>
</course>
我知道这听起来像是基本的 PHP,但这也差不多。例如,我如何只用 PHP 制作这个文件?
【问题讨论】:
-
使用 simpleXML php.net/manual/en/book.simplexml.php 。它是众多 php xml 库之一
-
一个简单的模板引擎(即 twig)也很有用。