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

Commit5a64d99

Browse files
committed
Main update -> Updated arg handling
1 parent6f8a16f commit5a64d99

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* It is a console application with var args
33
* Uses the traditional methodology to generate the xml (without a library), through
44
of nodes and tree structure.
5-
* Can read ANY CSV File
6-
* Args are:
5+
* Can read ANY CSV File (comma-separated & semicolon-separated)
6+
7+
Args are:
78
-[0] Input file
89
-[1] Output file
910
-[2] Element node name and optionally,

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

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33

44
importorg.w3c.dom.Document;
5-
importjavax.xml.parsers.ParserConfigurationException;
6-
importjavax.xml.transform.TransformerException;
7-
importjava.io.IOException;
8-
importjava.util.ArrayList;
95
importjava.util.List;
106
importjava.util.logging.Level;
117
importjava.util.logging.Logger;
@@ -23,35 +19,20 @@ public class Main {
2319
publicstaticvoidmain(String[]args) {
2420

2521
//Arg validator
26-
if (args.length==0) {
22+
if (args.length<2) {
2723
logger.log(Level.SEVERE,"No args were specified.");
28-
System.exit(0);
24+
System.exit(1);
2925
}
3026
//Vars Initialization
3127
StringcsvFile =args[0];
3228
StringxmlFile =args[1];
33-
StringelementName;
34-
StringcsvSplit =",(?=([^\"]*\"[^\"]*\")*[^\"]*$)";
35-
36-
try {
37-
elementName =args[2];
38-
}catch (ArrayIndexOutOfBoundsExceptione) {
39-
logger.log(Level.INFO,"Since you didn't specify a element name, 'element' will be the parental node.");
40-
elementName ="element";
41-
}
42-
43-
try {
44-
if (args[3] =="-s")
45-
csvSplit =";(?=([^\"]*\"[^\"]*\")*[^\"]*$)";
46-
}catch (ArrayIndexOutOfBoundsExceptione){
47-
}
29+
StringelementName =args.length>=3 && !args[3].equals("-s") ?args[2] :"element";
30+
StringcsvSplit = (args.length>3 &&args[3].equals("-s") ||args.length>4 &&args[4].equals("-s")) ?";(?=([^\"]*\"[^\"]*\")*[^\"]*$)":",(?=([^\"]*\"[^\"]*\")*[^\"]*$)";
4831

49-
List<String[]>elements;
50-
elements =XMLutils.readCsvFile(csvFile,csvSplit);
51-
DocumentxmlDoc;
52-
xmlDoc =XMLutils.createXmlDocument(elements,elementName);
53-
XMLutils.writeXmlDocumentToFile(xmlDoc,xmlFile);
54-
}
32+
List <String[]>elements =XMLutils.readCsvFile(csvFile,csvSplit);
33+
DocumentxmlDoc =XMLutils.createXmlDocument(elements,elementName);
34+
XMLutils.writeXmlDocumentToFile(xmlDoc,xmlFile);
35+
}
5536
}
5637

5738

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp