LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read string between two characters

Solved!
Go to solution

Nando didn't say what he actually wants, so an example is kind of tricky. He was talking about getting all the "text", but that's not usually relevant, as XML is a structured format, generally represesnted as a tree. For instance, here's a prettified section of the original file (there's no shortage of prettifying services):

 

    <eainfo>
        <detailed Name="Botaderos_2014_Union_Union">
            <enttyp>
                <enttypl Sync="TRUE">Botaderos_2014_Union_Union</enttypl>
                <enttypt Sync="TRUE">Feature Class</enttypt>
                <enttypc Sync="TRUE">0</enttypc>
            </enttyp>
            <attr>
                <attrlabl Sync="TRUE">OBJECTID_1</attrlabl>
                <attalias Sync="TRUE">OBJECTID_1</attalias>
                <attrtype Sync="TRUE">OID</attrtype>
                <attwidth Sync="TRUE">4</attwidth>
                <atprecis Sync="TRUE">0</atprecis>
                <attscale Sync="TRUE">0</attscale>
                <attrdef Sync="TRUE">Internal feature number.</attrdef>
                <attrdefs Sync="TRUE">Esri</attrdefs>
                <attrdomv>
                    <udom Sync="TRUE">Sequential unique whole numbers that are automatically generated.</udom>
                </attrdomv>
            </attr>
            <attr>
                <attrlabl Sync="TRUE">Shape</attrlabl>
                <attalias Sync="TRUE">Shape</attalias>
                <attrtype Sync="TRUE">Geometry</attrtype>
                <attwidth Sync="TRUE">0</attwidth>
                <atprecis Sync="TRUE">0</atprecis>
                <attscale Sync="TRUE">0</attscale>
                <attrdef Sync="TRUE">Feature geometry.</attrdef>
                <attrdefs Sync="TRUE">Esri</attrdefs>
                <attrdomv>
                    <udom Sync="TRUE">Coordinates defining the features.</udom>
                </attrdomv>
            </attr>
            <attr>
                <attrlabl Sync="TRUE">FID_Botaderos_2014_Union</attrlabl>
                <attalias Sync="TRUE">FID_Botaderos_2014_Union</attalias>
                <attrtype Sync="TRUE">Integer</attrtype>
                <attwidth Sync="TRUE">4</attwidth>

 

You could use XPath expressions to get all the attr elements, or to get a specific one or anything else that you want, but you would need to know what you want. Tools like EasyXML or Unflatten to XML usually just take the information and use it to populate an equivalent cluster that you feed in.

 

If this is important to you, I would suggest reading up on XML, DOMs, etc. If not, you could just try using something like EasyXML to import the values into a cluster which matches the data.


___________________
Try to take over the world!
0 Kudos
Message 11 of 22
(2,051 Views)

I am parsing the xml the way blokk suggested, since I am unable to use the example provided by billko. I can view all the values of the 1d array in the probe, but I am unable to display those values in the front panel. What I am trying to do is extract some specific data from the xml, but right now, I just want to display all the strings that match the expression that blokk suggested in the second reply for this question.

Can someone please tell me how I can fix this?

I will leave the screenshots of what I am doing.

Thanks in advance!

Download All
0 Kudos
Message 12 of 22
(2,028 Views)

I changed my block diagram, but now, I am only able to view 2 lines of text, and there should be more matches.

Can someone help me fix this error?

I will leave the snapshots of my front panel and block diagram, so you can see what I mean, and I will also leave the txt file.

Thanks in advance!

Download All
0 Kudos
Message 13 of 22
(2,013 Views)

From what I can see, you are going about it the hard way.  Take the time to look at the xml parsing example.  And going to w3school helps a lot, too.  🙂

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 14 of 22
(2,005 Views)

open your text file with this example vi 
it will do that for you 

0 Kudos
Message 15 of 22
(1,987 Views)

Hatef: This is not what the OP wants, your example does not do that.

 

Nando88: First of all, you should use XML approach as above suggested, I will try to find a working example. Second, as I see you have basic problems with your coding when I look at your screenshots (by the way, you should use LabVIEW snippets, so others can easier help you: http://www.ni.com/tutorial/9330/en/ ).

First try to work only with a single xml file, and get a working solution. You show that you try to get first all xml files inside a folder, and work on these files. In this case, if you want to use my example (but you should not, try proper xml approach 🙂 ), then you need to integrate my "solution" into your FOR loop which indexes through the xml files inside the folder. So you should have a while loop inside the FOR loop, and in the end the result will be a 2D string array.

 

Anyway, as I see you have other problems with your code, based on your screenshots (using a double (??) for a case structure via a shift register, many Boolean controls which do not have any purpose...).

Message 16 of 22
(1,968 Views)

So, I try to give a initial push to start learning xml, I never did, but it looks fun 🙂

Here is some learning material:

http://www.w3schools.com/xsl/xpath_syntax.asp

 

Here is a first example which I put quickly together, after some try&fail, but hopefully it will give you some initial idea which way to go to extract out those

info which you only need (I guess you have a list of parameters which you want to get from the xml?).

In the example below, if you are sure there are only single elements, you can just take the first column of the 2D array...And there are other ways, but first please only create a solution for a SINGLE xml file, and post it here. We can have a look, and after the next step should be only to extend the solution for multiple xml files inside a folder!

 

XPath_example1.png

 

Message 17 of 22
(1,954 Views)

It's always fun when you learn something new.  🙂

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 18 of 22
(1,943 Views)
Blokk thank you for your attention
could you tell me so what OP want
it is what i understand from this text
" I want to be able to read every line in the text file and display the text that is between "></""
my example read every line and then display text that is between <> ?!
0 Kudos
Message 19 of 22
(1,932 Views)

@Hatef.fouladi wrote:
Blokk thank you for your attention
could you tell me so what OP want
it is what i understand from this text
" I want to be able to read every line in the text file and display the text that is between "></""
my example read every line and then display text that is between <> ?!

The OP wants to extract data from XML files. You can do this properly using xml file operations, and not handling the xml as a text file only.

Second, you even misinterpreted what the OP wrote: "></". You used the "<>" markers. Moreover, your "solution" extracts lots of unneccesary text too. It is just simply wrong.

The OP can just easily use xml functions, after some playing with the XPath syntaxes.

Message 20 of 22
(1,923 Views)