XML vs text configuration files in Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

XML vs text configuration files in Java

Is there any benefit of using XML instead of regular text to store configuration, which user can modify by using Web GUI? Let's say I have a list of files I need Java app to check attributes of and user who runs the check via Web GUI can edit the list. Thanks in advance!

12th Dec 2016, 2:57 AM
Andrey Kitsa
Andrey Kitsa - avatar
5 Answers
+ 1
GUI is Graphical User Interface. Web GUI means a Web page with interface with a user. One of the benefits that I am aware of I using xml is schemas. It's easier to validate xml file against xsd. This reduces errors and allow control it for admin who do not have documentation. By simple look at scheme you can tell what and how to edit. But the benefit of text is its simplicity. Easier to parse and modify with Java code. I was more curious to hear from professional about all cons and pros
16th Dec 2016, 7:08 AM
Andrey Kitsa
Andrey Kitsa - avatar
+ 1
Hey, no problem on the language - I fully appreciate how hard it can be (I live in a non-English speaking country where I am busy learning the language). Fortunately programming is easier! Well spotted on the XML errors! (the 2nd one was unintentional - I was trying to shorten the post since it was too long). But I think you get the point - it is easy for XML files to become corrupted if they have to be "hand-edited" by users - especially if the users are not computer-savvy. There are other formats besides XML/JSON/INI you can consider as well - look at https://sdlang.org/. Just for the record - I have nothing against XML as long as any modification to the actual XML file is done by the app, and not "by hand".
16th Dec 2016, 11:09 AM
Ettienne Gilbert
Ettienne Gilbert - avatar
0
Not sure what a Web GUI is... a web browser? Generally XML is very good to use for configuration info read and set by a program. But not so good if a human has to read or set it "by hand", since someone not familiar with the format can easily introduce a formatting error which means your XML will not be "well formatted" anymore. JSON is a better format in this regard but for just a list of files I'll just use a good old INI file.
16th Dec 2016, 6:54 AM
Ettienne Gilbert
Ettienne Gilbert - avatar
0
Good grief! Looking for professionals on this website will eliminate 80+% of your audience! But you were lucky :), and since you made it now a requirement to answer the question: Yes I am and have been a professional sw developer for 20+ years. And have written/worked on literally 100s if not 1000s of apps (some well over 50KLOC). The main reason I am on this website is to answer questions as my little contribution to free and open education. You are making a classic reasoning mistake - you are dismissing my answer because (you think) my request back to you to clarify shows ignorance. So lets start: I know very well what a GUI is. But the way you refer to "Web GUI" applications is quite ambiguous, since this includes literally everything that connects to the web (including Android apps). There is a big difference in how Java apps handle a GUI using Swing/AWT/Eclipse RCP/etc and what a Java applet can do from inside a browser. Besides, we typically talk of applications as "having a GUI", not "is a" GUI. I am not even sure it makes sense to talk about a "GUI app", since virtually all PC apps (with the exception of Console apps, scripts and OS specialized things like device drivers, kernels, etc) have GUIs. Also: I know XML very well (including rolling my own parser using http://tibleiz.net/asm-xml/ since a standard DOM/SAX parser is way too slow for some of our domains). You actually missed my whole point: Schemas/XSD will not help you if your XML document is not well formed (https://en.wikipedia.org/wiki/Well-formed_document). So here is a very short sample of a XML config file : <MaskParameter address="0xA30D0" id="PatchBaseAddress" length="4"> <SubParam id="block10" items="2"/> <SubCParam id="blockSize" value="256bytes"/> <SubCParam id="blockStartAddress" value="0xA3AD0"/> </SubCParam> </MaskCardParameter> Spot the error (even with nice indenting)? If I had your use case and since I am lazy and prefer simple over complex I would simply use an INI file.
16th Dec 2016, 10:30 AM
Ettienne Gilbert
Ettienne Gilbert - avatar
0
Thanks for pointing to my mistakes in explaining stuff. English is my 3rd language and programming is something I am just starting. But you made a point. Also you have 2 errors in xml. Extra closing tag 2nd line from bottom and wrong tag name in last line. I read a wiki on json today. So I can answer a bit more on my question. The only difference I noticed is that xml allows comments.
16th Dec 2016, 10:39 AM
Andrey Kitsa
Andrey Kitsa - avatar