LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read xml files in directory, then extract words from them

Solved!
Go to solution

I have searched the LabView forums for a similar problem to mine, but I have been unsuccessful in finding the advice I need.

 

Some time ago, I wrote a LabView programme to build a dictionary from an array of strings.  It was really just a list of words which I used to make a crude search engine.

 

Right now, I am trying to repeat this experiment.  However, I am stuck at the first hurdle.  I have a directory containing a number of folders and files including some .xml files.

 

What I need to do is read the individual words out of the xml files and then amalgamate the words into one big list.  From here on, I should be able to make the dictionary and I hope that my old search engine will still work with the new data.

 

The attachment shows my unsuccessful attempt to create a VI that can first index all of the files in a directory (which it does do) and then list only the files ending '.xml' (which it does not do). 

 

Any advice about how to get my list of words out would be greatly appreciated!

 

Adam

0 Kudos
Message 1 of 6
(2,855 Views)
Solution
Accepted by topic author AdamEdinburgh

Is this what you are looking for? (See attached VI image)

TailOfGon
Certified LabVIEW Architect 2013
0 Kudos
Message 2 of 6
(2,842 Views)

Thank you!  🙂

 

(you can tell that I have been away from LabView for a while!)

 

Forehead, meet palm.  You guys are going to be spending a lot of time together...

0 Kudos
Message 3 of 6
(2,814 Views)

 

Sadly, I am stuck at the next step.  I have extracted the xml as a string - and I am able to do this for all the xml documents in my set.  However, I want to remove all of the xml code so that I just have text. 

 

I have read a number of xml parsing threads, which are bound to become very useful later, but none of them seem to cover this problem (which seems like it should be very trivial).

 

If anyone can offer any advice, I would be very grateful.

 

I would also be glad to have any advice about how I can find this kind of information without troubling other forum users.  I am sure this must have been covered in another forum post somewhere; I just can't find it.

 

Many thanks

 

Adam

0 Kudos
Message 4 of 6
(2,771 Views)

Hi, Adam

 

There are several ways that I can think of to accomplish what you want to do. The solution best fit for you depends on what you use to open a xml file.

 

1. If you use basic file I/O functions to read your xml files:

 

then you will need to use Search and Replace your xml string by using Regular Expression. If you do not know what it is, think of it as a advanced way to search within a text using wildcards. I really really recommend you to take some time to learn this as it helps your string manipulation in general.

 

For example, if you want to remove all the xml tags like "<abc>" or "</abc>, it can be easily done by using a Search and Replace String function:

 

In Search and Replace String node:

>>input string = your xml string

>>search string = "<[^>]*>" (do not include double quotes)

>>replace all? = True

(You may need to right click on the node and switch to 'Regular Expression' mode)

 

2. If you use xml parser, then it is simple enough just to use "Text" method of the XML object to extract all xml tags and get a string.

 

If you are using this option and have troubles doing it as you wish, let me know.

 

Thanks.

 

SK

TailOfGon
Certified LabVIEW Architect 2013
Message 5 of 6
(2,765 Views)

Thanks!

 

This works really well.  I just have a few more steps to go through before my dictionary is complete. 

0 Kudos
Message 6 of 6
(2,738 Views)