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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read string between two characters

Solved!
Go to solution

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.

0 Kudos
Message 1 of 22
(6,476 Views)
Solution
Accepted by topic author Nando88

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

 

XML_data_extract.png

0 Kudos
Message 2 of 22
(6,427 Views)

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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 22
(6,408 Views)

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

0 Kudos
Message 4 of 22
(6,382 Views)

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

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 22
(6,357 Views)
Can someone please give me an example on how to use GXML to parse an xml file that was not created in Labview?
I am just starting to learn how to work with xml files in labview and would really appreciate all the help I can get.
0 Kudos
Message 6 of 22
(6,329 Views)

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.


___________________
Try to take over the world!
0 Kudos
Message 7 of 22
(6,278 Views)

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

0 Kudos
Message 8 of 22
(6,259 Views)

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.


___________________
Try to take over the world!
0 Kudos
Message 9 of 22
(6,240 Views)
I see. I never worked with xmls, would be interesting to see an example...
0 Kudos
Message 10 of 22
(6,235 Views)