Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf405b34

Browse files
author
A. Apesteguia
committed
Patch MainReader and Tabular
1 parent88715df commitf405b34

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

‎src/main/java/com/codepressed/CSVtoXML/Main.java‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
publicclassMain {
1010
/**
1111
* Executes the CSV to XML conversion
12-
* @param args file input and output
13-
*
12+
* @author Daniel Apesteguia Timoner
13+
* @param args Input file, output file and elements names.
1414
*/
1515
publicstaticvoidmain(String[]args){
1616
//Arg validator
@@ -24,14 +24,21 @@ public static void main(String[] args){
2424
//Vars Initialization
2525
StringcsvFile =args[0];
2626
StringxmlFile =args[1];
27-
StringelementName =args[2];
27+
StringelementName;
28+
try{
29+
elementName =args[2];}
30+
catch (ArrayIndexOutOfBoundsExceptione){
31+
System.out.println("You didn't especify any element so we will fix 'element' as parental node.");
32+
elementName ="element";
33+
}
34+
2835

2936
//ArrayList of ArrayStrings Generation with CSV
30-
ArrayList<String[]>elements =null;
37+
ArrayList<String[]>elements;
3138
elements =newReader().CSVtoArrayList(csvFile);
3239

3340
//XML Doc Generation with ArrayList
34-
DocumentxmlDoc =null;
41+
DocumentxmlDoc;
3542
xmlDoc =newTabularToXMLConverter().docBuilder(elements,elementName);
3643
TabularToXMLConverter.transformDocToFile(xmlDoc,xmlFile);
3744

@@ -40,7 +47,7 @@ public static void main(String[] args){
4047
System.out.println("File wasn't found, error: "+e);
4148
}
4249
catch (TransformerExceptione){
43-
System.out.println("Transformer error: "+e);;
50+
System.out.println("Transformer error: "+e);
4451
}
4552
catch (ParserConfigurationExceptione) {
4653
System.out.println("Configuration error: "+e);

‎src/main/java/com/codepressed/CSVtoXML/Reader.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public class Reader {
1010
publicArrayList<String[]>CSVtoArrayList(StringcsvFile)throwsIOException {
1111
ArrayList<String[]>elements =newArrayList<String[]>();
1212
StringcsvSplit =",(?=([^\"]*\"[^\"]*\")*[^\"]*$)";
13-
Stringline ="";
1413
BufferedReadercsvReader =null;
14+
Stringline;
1515

1616
try {
1717
csvReader =newBufferedReader(newFileReader(csvFile));

‎src/main/java/com/codepressed/CSVtoXML/TabularToXMLConverter.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ public class TabularToXMLConverter {
1919

2020
//DOC Generation -> XML with ArrayList String elements
2121
publicDocumentdocBuilder(ArrayList<String[]>XMLelements,StringelementName)throwsParserConfigurationException {
22+
if (elementName ==null){
23+
elementName ="element";
24+
}
2225
DocumentBuilderFactoryxmlFactory =DocumentBuilderFactory.newInstance();
2326
DocumentBuilderxmlBuilder =xmlFactory.newDocumentBuilder();
2427
DocumentxmlDoc =xmlBuilder.newDocument();
2528

2629
ElementrootElement =xmlDoc.createElement("root");
2730
xmlDoc.appendChild(rootElement);
28-
2931
ElementmainElement =xmlDoc.createElement(elementName+"s");
3032
rootElement.appendChild(mainElement);
3133

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp