-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportXML.php
62 lines (62 loc) · 1.93 KB
/
exportXML.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
include("dbconfig.php");
$tables = array("Account","Annotation","Blog","CircleAccessRight","CircleMembership","Collection","Comment","FriendAccessRight","FriendCircle","Friendship","Photo","Invitation","Message","Recommendation");
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$xml .= "<!DOCTYPE note SYSTEM \"note.dtd\">"; //try
$xml .="<note
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">";
$xml .= "<tables>";
foreach ($tables as $table_name) {
$table = $table_name."s";
$xml .= "<$table>";
$sql = "SELECT * FROM ".$table_name;
$result = mysqli_query($conn,$sql);
if (!$result) {
die('Invalid query');
}
if(mysqli_num_rows($result)>0){
while($result_array = mysqli_fetch_assoc($result)){
$xml .= "<".$table_name.">";
foreach($result_array as $key => $value){
if ($key=='image') {
$xml .= "<$key>";
$xml .= "<![CDATA[".base64_encode($value)."]]>";
$xml .= "</$key>";
}else {
if (!is_null($value) ) {
$xml .= "<$key>";
$xml .= "<![CDATA[$value]]>";
$xml .= "</$key>";
}else{
$xml .= "<$key xsi:nil=\"true\" />";
}
}
}
$xml.="</".$table_name.">";
}
}
$xml .= "</$table>";
}
$xml .= "</tables>";
$xml .="</note>";
file_put_contents("export.xml", $xml);
mysqli_close($conn);
?>
<html>
<head>
<title>Export XML</title>
<?php require_once('head.php'); ?>
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1>Assignment Book</h1>
<p>Export XML</p>
</div>
<a href="export.xml" class = "btn btn-default" role="button" download>Download the xml</a>
<a href ="index.php" class = "btn btn-default" role="button" >Back to homepage</a>
<br><br/>
</div>
<?php require_once('common_footer.html');?>
</body>
</html>