Skip to content

Commit 532e2a2

Browse files
committed
XML Exportation Support
1 parent f2aad99 commit 532e2a2

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Release.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
![AnDatabase v2.3 JRE 9.jar ](https://github.com/anongrp/AnDatabase/raw/master/Release/AN%20Database%20v2.3%20JRE%209.jar)
44
![AnDatabase v2.2 JRE 9.jar](https://github.com/anongrp/AnDatabase/raw/master/Release/AN%20Database%20v2.2%20JRE%209%20.jar)
55
![AnDatabase v2.2 JRE 8.jar](https://github.com/anongrp/AnDatabase/raw/master/Release/AN%20Database%20v2.2%20JRE%208%20.jar)
6-
![AnDatabase v2.1jar](https://github.com/anongrp/AnDatabase/raw/master/Release/AN%20Database%20v2.1.jar)
7-
6+
![AnDatabase v2.1jar](https://github.com/anongrp/AnDatabase/raw/master/Release/AN%20Database%20v2.1.jar)

src/Main.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import anon.database.exceptions.DatabaseConnectionException;
55
import anon.database.exceptions.NoTableFoundException;
66
import anon.database.exceptions.TableCreationOutOfBoundException;
7+
78
import java.io.File;
89
import java.io.IOException;
910

@@ -22,8 +23,6 @@ public static void main(String[] args) throws IOException, TableCreationOutOfBou
2223
System.out.println("Some Erro");
2324
}
2425

25-
for (int i=0 ;i<=100000;i++){
26-
login_tb.insertRow(data);
27-
}
26+
System.out.println(login_tb.exportToXML(new File("C:/Users/Anikesh/Desktop/data.xml")));
2827
}
2928
}

src/anon/database/Table.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ private void createTable(String tbName, Database database,String columnNames[])
5252
writeColumnData.write("¤");
5353
writeColumnData.close();
5454
}
55+
5556
}
5657

5758

@@ -180,6 +181,7 @@ public boolean deleteElementWithQuery(String query) throws IOException {
180181
}
181182

182183
public boolean deleteElement(String colName,String target) throws IOException {
184+
183185
boolean deleteStatus = false;
184186
String deleteRow = "";
185187
ArrayList<String> rows = new ArrayList<String>();
@@ -425,6 +427,42 @@ public boolean exportToJSON(File jsonFile) throws IOException {
425427
return status;
426428
}
427429

430+
public boolean exportToXML(File xmlFile) throws IOException {
431+
boolean status = false;
432+
final String TAG_OPENING = "<";
433+
final String TAG_CLOSING = ">";
434+
final String TAG_OPENING_WITH_CLOSE = "</";
435+
final String NEW_LINE_SEPARATOR = "\n";
436+
final String SINGLE_TAB = "\t";
437+
final String DOUBLE_TAB = "\t\t";
438+
ArrayList<ArrayList<String>> tabelData = this.getFullTable();
439+
FileWriter writer = null;
440+
Integer count = 0;
441+
try {
442+
xmlFile.createNewFile();
443+
writer = new FileWriter(xmlFile);
444+
writer.append(TAG_OPENING+"Table"+TAG_CLOSING);
445+
for (ArrayList<String> row: tabelData){
446+
count++;
447+
if (count != 1){
448+
writer.append(NEW_LINE_SEPARATOR+SINGLE_TAB+TAG_OPENING+"row key="+row.get(0)+TAG_CLOSING+NEW_LINE_SEPARATOR);
449+
for (int i=1;i<row.size();i++){
450+
writer.append(DOUBLE_TAB+TAG_OPENING+"data"+TAG_CLOSING+row.get(i)+TAG_OPENING_WITH_CLOSE+"data"+TAG_CLOSING+NEW_LINE_SEPARATOR);
451+
}
452+
writer.append(SINGLE_TAB+TAG_OPENING_WITH_CLOSE+"row"+TAG_CLOSING);
453+
}
454+
}
455+
writer.append(NEW_LINE_SEPARATOR+TAG_OPENING_WITH_CLOSE+"Table"+TAG_CLOSING);
456+
}catch (Exception e){
457+
status = false;
458+
}finally {
459+
writer.close();
460+
}
461+
462+
return status;
463+
}
464+
465+
428466
@Override
429467
public String toString() {
430468
ArrayList<ArrayList<String>> list = null;

src/anon/database/connect/Connection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public static boolean connect(String projectName){
2121
dbLocation = "/home/"+System.getProperty("user.name")+File.separator+"."+projectName;
2222
Connection.status = true;
2323
}
24+
25+
2426
return initSpace();
2527
}
2628

0 commit comments

Comments
 (0)