04-07-2020 10:50 AM
Just from some quick googling I understand how XML is formatted, I just cant understand how and where I would use it in programs.
I'm mostly communicating and controlling instruments. datalogging. Would using xml instead of say a .txt or .ini file be helpful?
04-07-2020 11:07 AM
I have started using XML for my instrument configurations. The reason I have started going with XML is because it has a hierarchy to it. txt and ini files are generally flat in hierarchy.
04-07-2020 11:17 AM
@crossrulz wrote:
I have started using XML for my instrument configurations. The reason I have started going with XML is because it has a hierarchy to it. txt and ini files are generally flat in hierarchy.
I prefer JSON over XML because I think it is easier to read for a human. Both XML and JSON are good for communicating between systems when a pure binary form would not be feasible. If a human needs to interact with the file then as I mentioned, I think JSON is easier to read for humans.
04-07-2020 11:25 AM
I put config info in classes, then save the class to XML to get the benefit of automutation.
04-07-2020 11:27 AM - edited 04-07-2020 11:29 AM
OK I understand now.
Not only is it organized and structured more efficiently, it's human readable and it can also be used to communicate between systems, Thank you!
My previous use of having configuration.ini files can be replaced with configuration.xml files. A user can open this and it is easier to understand and edit it.
04-07-2020 11:36 AM - edited 04-07-2020 11:37 AM
@paul_cardinale wrote:
I put config info in classes, then save the class to XML to get the benefit of automutation.
Doesn't saving the class as XML add a bunch of other stuff to the XML? I try to avoid putting too much extra stuff in config files that the user may muck with and end up breaking something. And if it has LabVIEW class stuff included, this makes the XML file much more LabVIEW specific and not as generic.
Either way, I still prefer JSON over XML.
04-07-2020 11:36 AM
If you are going to use XML, I highly recommend you install XML Notepad. It is a very useful tool for viewing and editing XML files.
04-07-2020 11:41 AM
@crossrulz wrote:
If you are going to use XML, I highly recommend you install XML Notepad. It is a very useful tool for viewing and editing XML files.
I use Notepad++, which allows me to work with XML easier. However, my general rule of thumb is to assume that the end user doesn't have any special tools or applications so I envision them using Notepad to edit the file. Given this, I opt for JSON format since I feel it is more human readable in its raw form than XML. Both server there purpose.
One other benefit of JSON is that it actually requires less bytes than XML. So if you are doing lots of transfer of data between applications or components of the system this may be a factor to consider as well.
04-07-2020 12:01 PM
I have been using sublime text to edit those kinds of files. I might need a plugin to indent it properly.
I just googled a JSON and XML for a student hierarchy. It does seem like the JSON is a bit more human readable but they both offer much more than I previously was using.
{ "student": [ { "id":"01", "name": "Tom", "lastname": "Price" }, { "id":"02", "name": "Nick", "lastname": "Thameson" } ] }
Let's study the same code in XML
<?xml version="1.0" encoding="UTF-8" ?> <root> <student> <id>01</id> <name>Tom</name> <lastname>Price</lastname> </student> <student> <id>02</id> <name>Nick</name> <lastname>Thameson</lastname> </student> </root>
04-07-2020 12:11 PM
You can still do hierarchical stuff in an ini file of course, but in it's nature, it's not that hierarchical:
[level 1]
level 2 = ...
level 2.level 3 =
level 2.level 3.level 4 =
If you just need something hierarchy, I'd go with JSON.
XML does have a lot of advanced features that JSON just doesn't have. Like stylesheets to automatically convert from one XML file to a completely different XML file. Or automatic validation with XLS or DTD files. Or references to external files. Support for encoding. All stuff that make it really hard to fully understand, but it's there for a reason. I'm sure JSON will have or get solutions to deal with these issues, but it's not handled at JSON level.
That's actually one of the big disadvantages of XML (over JSON). The XML spec is vast, like thousands of pages. The entire JSON spec fits on a single side of paper, at normal text size. This makes JSON very accessible. You can actually learn and understand the entire JSON spec in a few days.