Page 1 of 1

extract data from socket?

Posted: Wed Oct 25, 2017 5:15 am
by tusa
Hello.

Right now i'm able to send a command to a socket and I recieve this:

Code: Select all

201 INFO TEMPLATE OK
<?xml version="1.0" encoding="utf-8"?>
<template version="2.0.0" authorName="Tue Sandbæk" authorEmail="tue@broadcastsupport.dk" templateInfo="TV SYD, KV17 credit" originalWidth="1920" originalHeight="1080" originalFrameRate="50">
   <components>
      <component name="CasparTextField">
         <property name="text" type="string" info="String data"/>
      </component>
   </components>
   <keyframes/>
   <instances>
      <instance name="f1" type="CasparTextField"/>
      <instance name="f0" type="CasparTextField"/>
   </instances>
   <parameters/>
</template>
I need to search for the number of instance name and regarding on the number of intances I want to show (in this example 2) rows in a datagrid, that I can fill in with data.

Brg Tue.

Re: extract data from socket?

Posted: Wed Oct 25, 2017 11:20 am
by Klaus
Hi Tusa,

here my easy-peasy solution without regex:

Code: Select all

on mouseUp
   ## I put your XML into field 1 of my little test stack
   put fld 1 into tData
   filter lines of tData with "*<instance name=*"
   put the num of lines of tData
end mouseUp
and it reported 2 as exspected. :D

Best

Klaus

Re: extract data from socket?

Posted: Thu Oct 26, 2017 7:01 am
by tusa
With that piece of code I now managed to get the two lines:

Code: Select all

<instance name="f1" type="CasparTextField"/>
<instance name="f0" type="CasparTextField"/>
inside a field, but i need pass the "f0" and "f1" on two lines in a datagrid.
So I guess I have to extract only what's inside the instance name="" into something?

Re: extract data from socket?

Posted: Thu Oct 26, 2017 7:51 am
by Thierry
tusa wrote:
Thu Oct 26, 2017 7:01 am
but i need pass the "f0" and "f1" on two lines in a datagrid.
So I guess I have to extract only what's inside the instance name="" into something?
Try this code in a button:

Code: Select all

on mouseup
local tData, R
   put line -16 to -2 of the script of me into tData
   filter lines of tData with regex pattern "<instance name="
   repeat for each line L in tData
      if matchText( L, "\sname=.(.+?).\s", aNameValue) then
         -- do whatever you like with aNameValue -> f0, f1,...
         put "found: " & aNameValue &cr after R
      end if
   end repeat
   put R
end mouseUp

/*
201 INFO TEMPLATE OK
<?xml version="1.0" encoding="utf-8"?>
<template version="2.0.0" authorName="Tue Sandbæk" authorEmail="tue@broadcastsupport.dk" templateInfo="TV SYD, KV17 credit" originalWidth="1920" originalHeight="1080" originalFrameRate="50">
<components>
<component name="CasparTextField">
<property name="text" type="string" info="String data"/>
</component>
</components>
<keyframes/>
<instances>
<instance name="f1" type="CasparTextField"/>
<instance name="f0" type="CasparTextField"/>
</instances>
<parameters/>
</template>
*/

There is, as often with LC, few ways to love a cat...
Hopefully, someone will come using offset (check in the dictionary)

HTH,

Thierry

Re: extract data from socket?

Posted: Thu Oct 26, 2017 10:26 am
by Klaus
Oh, sorry, I missed the "name" part...