1515import java .io .FileOutputStream ;
1616import java .util .ArrayList ;
1717
18- public class Util {
18+ public class TabularToXMLConverter {
1919
20- /*/
21- DOC Generation -> XML with ArrayList String elements
22- */
23- public Document docBuilder (ArrayList <String []>elements )throws ParserConfigurationException {
20+ //DOC Generation -> XML with ArrayList String elements
21+ public Document docBuilder (ArrayList <String []>XMLelements ,String elementName )throws ParserConfigurationException {
2422DocumentBuilderFactory xmlFactory =DocumentBuilderFactory .newInstance ();
2523DocumentBuilder xmlBuilder =xmlFactory .newDocumentBuilder ();
2624Document xmlDoc =xmlBuilder .newDocument ();
2725
2826Element rootElement =xmlDoc .createElement ("root" );
2927xmlDoc .appendChild (rootElement );
3028
31- Element mainElement =xmlDoc .createElement ("elements " );
29+ Element mainElement =xmlDoc .createElement (elementName + "s " );
3230rootElement .appendChild (mainElement );
3331
3432boolean headerDefined =false ;//First while will be to define header
35- String []header =new String [elements .size ()];//Header initialization
33+ String []header =new String [XMLelements .size ()];//Header initialization
3634
37- /*/
38- DOC Generation -> XML Generation of every ELEMENT
39- */
40- for (String []node :elements ) {//FOR every ArrayString
35+ //DOC Generation -> XML Generation of every ELEMENT
36+ for (String []node :XMLelements ) {//FOR every ArrayString
4137if (headerDefined ) {
42- Element nodesElements =xmlDoc .createElement ("element" );
38+ Element nodesElements =xmlDoc .createElement (elementName );
4339mainElement .appendChild (nodesElements );
4440
4541for (int j =0 ;j <node .length ;j ++) {
@@ -50,17 +46,15 @@ public Document docBuilder(ArrayList<String[]> elements) throws ParserConfigurat
5046nodesValues .appendChild (nodeTxt );
5147 }
5248 }
53- /*/
54- DOC Generation -> Array Generation of every COL Name for NODES
55- */
49+ //DOC Generation -> Array Generation of every COL Name for NODES
5650else {
5751header =node ;
58- for (int k =0 ;k <node .length ;k ++) {
59- header [k ] =header [k ].replaceAll ("[^a-zA-Z0-9]" ,"" );
60- //We want to make sure NODE isn't NUMERIC. If it is, we make a patch
52+ for (int j =0 ;j <node .length ;j ++) {
53+ header [j ] =header [j ].replaceAll ("[^a-zA-Z0-9]" ,"" );
54+ //Avoid a fullint
6155try {
62- Integer .parseInt (header [k ]);
63- header [k ] ="node" +header [k ];
56+ Integer .parseInt (header [j ]);
57+ header [j ] ="node" +header [j ];
6458 }catch (NumberFormatException e ) {
6559 }
6660 }
@@ -70,9 +64,7 @@ public Document docBuilder(ArrayList<String[]> elements) throws ParserConfigurat
7064return (xmlDoc );
7165 }
7266
73- /*/
74- XML Generation -> Transform DOC Data to XML Format
75- */
67+ //XML Generation -> Transform DOC Data to XML Format
7668public static void transformDocToFile (Document xmlDoc ,String xmlFile )throws TransformerException {
7769TransformerFactory xmlTransformerFactory =TransformerFactory .newInstance ();
7870Transformer xmlTransformer =xmlTransformerFactory .newTransformer ();