LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract values between <> in an array of strings and split into new arrays

Hi, 

 

I am having some difficulty trying to do the following. I have an array of strings and I need to split each string into separate arrays. e.g. 

 

Current string: 

 

<ENV_SCALE>18</ENV_SCALE>
<GAIN>1</GAIN>

 

Required Info: 

 

Array1                                         Array 2 

ENV_SCALE                             18

GAIN                                            1

 

The value between the <> and the >< can change depending on the string and the number of rows in a string can change. The example above has 2 but there can be up to 4 or 5 depending on the element of the array. Any help would be greatly appreciated! I was trying to use reg ex and use the following command <.+?> but that also grabs the <> and it seems like an inefficient way to process this. 

0 Kudos
Message 1 of 7
(3,830 Views)

Attach a VI that shows what you have done so far.

 

Regexes are complicated and powerful.  I'm sure there are ways to make sure it doesn't include the < and >.  Probably just a tweak to the expression.

0 Kudos
Message 2 of 7
(3,826 Views)

You would not by chande be starting with an XML file would you?

 


@syedzeeshan wrote:

 

Current string: 

 

<ENV_SCALE>18</ENV_SCALE>
<GAIN>1</GAIN>

 

 


 

Certainly looks like it...

 

You might want to search the examples fo how to use the LabVIEW XML parser.

 

When setup properly you can just search for the tags, like "ENV_SCALE" and it will return "18".

 

No need to parse strings looking for what is between > and <

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 7
(3,813 Views)

Almost looks like parsing XML.

 

I suggest breaking this up into two tasks -- convert the multi-line String to an Array of (single-line) strings (all of which start with a <> tag and end with the </> end tag) and then parsing the <Start Tag>Content<End Tag>.

 

For this second parse, start by finding <(anything)> (I'm using really sloppy terminology, but you should be able to understand what I mean).  You should be left with Content + End Tag, and should be able to create End Tag as </(anything)>.  Do the search for End Tag anyway -- if you don't find it, you've got a mal-formed string.  Otherwise, your Tag search will give you the Start Tag for Array 1 and the End Tag search will give you Content for Array 2.

 

Have Fun.

 

Bob Schor

Message 4 of 7
(3,808 Views)

This is a XML file. I cannot use the name i.e. ENV_SCALE since that changes based on the current content in the XML. I've shown an example of the main body of the XML file below and I processed it down to this data.

I've attached the way i process the XML to this.

<event>
    <trigger>
      <name>RTC</name>
      <value>0</value>
    </trigger>
    <module>
      <name></name>
      <type>REGISTER</type>
      <action>WRITE</action>
      <WMSS_EVENT_TIME>
        <EVT_TXFE0_SMP_D_UPDATE_TIME>
          <label></label>
          <VAL>0</VAL>
        </EVT_TXFE0_SMP_D_UPDATE_TIME>
      </WMSS_EVENT_TIME>
    </module>
    <module>
      <name></name>
      <type>REGISTER</type>
      <action>WRITE</action>
      <WMSS_EVENT_TIME>
        <EVT_TXFE0_SMP_D_UPDATE_TIME3>
          <label></label>
          <ENV_SCALE>18</ENV_SCALE>
          <TXFE_GAIN>1</TXFE_GAIN>
        </EVT_TXFE0_SMP_D_UPDATE_TIME3>
      </WMSS_EVENT_TIME>
    </module>
    <module>
      <name></name>
      <type>REGISTER</type>
      <action>WRITE</action>
      <WMSS_EVENT_TIME>
        <EVT_TXFE0_SMP_D_UPDATE_TIME1>
          <label></label>
          <ET_GAIN>23</ET_GAIN>
          <IQ_GAIN>25</IQ_GAIN>
        </EVT_TXFE0_SMP_D_UPDATE_TIME1>
      </WMSS_EVENT_TIME>
    </module>
    </event>

0 Kudos
Message 5 of 7
(3,800 Views)

This is a very different task than the one you originally posed, where tags were not nested inside other tags.

 

If your goal is to work with and parse XML, and if you are not reasonably expert in LabVIEW, string handling, XML, etc., then I strongly recommend that you use one of several XML parsers for LabVIEW (or, indeed, for some other language) to build structures for you.  Note that the example you finally show of an XML string does not easily "map" into the two-array formulation of your original question.

 

Bob Schor

0 Kudos
Message 6 of 7
(3,759 Views)

@syedzeeshan wrote:

This is a XML file. I cannot use the name i.e. ENV_SCALE since that changes based on the current content in the XML. I've shown an example of the main body of the XML file below and I processed it down to this data.

I've attached the way i process the XML to this.

 

The attached Vi Doesnot use XML Parser Properly you are extracting the XML String from the File and Doing String Manipulation

 

Please Go through Xpath Creation procedure

 

For Quick Note use XML Grid (google) and Find the xpath for your respective Value to extract

 

As you Mnetined only values will get chnaged and the Tag Name Reamins Same so use Tag NAme to extarct value


 

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 7
(3,737 Views)