From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
02-21-2016 08:23 AM
I have an xml file saved as a text file, and this xml was not generated in Labview. I want to be able to read every line in the text file and display the text that is between "></", so that I can use that information. Can someone please tell me how to do this?
I will leave the text file as an attachment.
Solved! Go to Solution.
02-21-2016 10:13 AM - edited 02-21-2016 10:15 AM
This might give you some hints, but you have to play with it more to get properly what you want. I am not really good in string manipulation and neither too familiar with regular expressions, sorry...
02-21-2016 10:45 AM - edited 02-21-2016 10:47 AM
LabVIEW has an example of how to parse out an xml file. Here's the help for parsing an xml file - which took me longer to post this info than it did to Google it.
http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/parsing_xml_files_in_lv/
That being said, the xml vi's that come with LabVIEW are sllllooooow and you'd be better off using a (free) third party xml package. I can't remember where I found it.
02-21-2016 11:01 AM
If you need an XML Parser, besides the one that comes with LabVIEW, there are two on the LabVIEW Tools Network (EasyXML, from JKISoft, and NI-GXML, which I use and like) as well as package mentioned here on the Forum, LabXML, that some have used. Note that parsing XML is a little more involved than just looking for things between <begin><\begin> tags, as there attributes, nesting tags, and sometimes only one of a pair (I forget what that's called ...).
Bob Schor
02-21-2016 12:07 PM
Oh, plus parsing an XML file is more robust than simply looking for a string. XML files are usually formatted with - well, a format - in mind. As a result, the same element or attribute is likely to occur several times as children to parent nodes. If you end up doing a text search like "search for the 3rd occurrence of this string, but only if this string comes before it, etc, etc" you may as well parse it out instead.
I admit it was a difficult learning curve for me, but once I figured it out, it was so easy to parse out everything I needed. In fact, it was so easy to parse, I ended up parsing out everything I thought I'd ever need also. (If you can parse out one child, why not all the other siblings, too? Of course, you have to balance this tendency with the fact that it could be a LOT of info that might take a while to parse - using the standard LabVIEW XML VIs, at least. With LabXML, I was able to parse the entire file in less time than it took to parse one element with the standard LabVIEW XML VIs.)
02-21-2016 01:43 PM
02-22-2016 03:06 AM
I haven't looked at your XML file and I'm far from an expert on working with XML, but I would suggest that you do use the built in functions. While they can be slow, as suggested, their performance improves considerably if you use XPath (read up on that) to get the information you want.
02-22-2016 04:15 AM
The problem is that, this file is not following the standard LabVIEW XML schema. At least when I tried to read the file with the shipped XML functions in LV, it did not work (no error msg neither).
02-22-2016 05:16 AM
I was talking about the parsing VIs Bill linked to above, not the Unflatten from XML primitive. The parsing VIs don't need the LV schema.
02-22-2016 05:18 AM