LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why would I use XML?

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?

0 Kudos
Message 1 of 11
(3,725 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 11
(3,712 Views)

@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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 11
(3,703 Views)

I put config info in classes, then save the class to XML to get the benefit of automutation.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 11
(3,697 Views)

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.

0 Kudos
Message 5 of 11
(3,693 Views)

@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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 11
(3,687 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 11
(3,686 Views)

@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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 8 of 11
(3,681 Views)

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>

 

Message 9 of 11
(3,669 Views)

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.

0 Kudos
Message 10 of 11
(3,665 Views)