July 30, 2019 at 13:05 #7112
I am using an Abekas MIRA playback/record server. It’s responses are formatted as an XML string. When I request a clip list from the machine, I would like to parse the response in order to use it for an Automatic Parameter in the Device Editor. From the attached example, I need to parse the clip names (highlighted in green) that are listed between all the <ClipID> and </ClipID> tags (highlighted in yellow). As I am not so familiar with BASIC commands, could someone help me figure out how to parse this information?
You must be logged in to access attached files.August 1, 2019 at 13:01 #7160JonasStadeParticipant
1. Use NthField() as a sorting function. Use <ClipId> as sorting identifier, then select slot 2, should be something like
dim clipid as string
And then you have two options. First you can set </clip> as an acknowledge in the command driver, so VControl stops reading the
Ioresult from this point on/cut the rest of the XML of, because it is the command end indicator, were the ack event would take over. Or you do another NthField request on </ClipId> and select slot 1. then fill the value into the device driver and you finish. Would be nice if you could response if it is working. The last time I write huge amount of text to this Forum and no working response etc.August 2, 2019 at 11:54 #7191Dierk WalterKeymaster
Jonas’ clue is absolutely correct. But we have the problem here that NthField is NOT case sensitive. And in your return string you have clipid and ClipID, which is the same for the NthField function. This makes it really complex to parse the string.Visual Basic123<reply>&h0D&h0A<xid>1</xid>&h0D&h0A<clipid>&h0D&h0A<ClipID>1027_A_UR</ClipID>&h0D&h0A</clipid>&h0D&h0A</reply><reply>&h0D&h0A<xid>1</xid>&h0D&h0A<clipid>&h0D&h0A<ClipID>4K GOLF COURSES\4k_MonWall_Course_Generic1_LEFT</ClipID>&h0D&h0A</clipid>&h0D&h0A</reply>
A full description of the clip looks like this:Visual Basic123<reply>&h0D&h0A<xid>1</xid>&h0D&h0A<clipid>&h0D&h0A<ClipID>1027_A_UR</ClipID>&h0D&h0A</clipid>&h0D&h0A</reply>
so you can loop through your result such asVisual Basic12345678910111213141516171819dim tmp as stringdim i as integerfor i = 1 to CountFields(ioresult,"</ClipID>"+chr(13)+chr(10)+"</clipid>"+chr(13)+chr(10)+"</reply>") -1'CountFields(ioresult,"</ClipID>"+chr(13)+chr(10)+"</clipid>"+chr(13)+chr(10)+"</reply>") returns number of clips +1tmp = NthField(tmp,"</ClipID>",1)'tmp = <reply>&h0D&h0A<xid>1</xid>&h0D&h0A<clipid>&h0D&h0A<ClipID>1027_A_UR'we can not use the NthField function to get the clipname bacause there is two times <clipid> in the string: <clipid> and <ClipID>'the replaceB function is case sensitive, so we use this function to make <ClipID> unique.tmp = replaceB(tmp,"<ClipID>",":")'tmp = <reply>&h0D&h0A<xid>1</xid>&h0D&h0A<clipid>&h0D&h0A:1027_A_UR'now we can use NthField to grab the clipnametmp = NthField(tmp,":",2)'tmp = 1027_A_UR'Do what ever you want to do with the clipnameNextAugust 2, 2019 at 12:48 #7196
Thank you Jonas and Dierk. I will try this as soon as possible.September 24, 2019 at 17:16 #8487
So I’ve had a chance to try your suggestions and am having some issues. My main issue right now is that the count I’m getting from CountFields is unreliable. The playback server has 519 clips in it and I get a different clip count every time I run it. For now, I am just testing CountFields as a command and not an ack command so that I can see what is going on. The other curious thing is that using ioresult in CountFields does not work for me. I have to declare a variable using the Received device variable. Any thoughts?
AlexSeptember 24, 2019 at 22:26 #8493DierkParticipant
If you have 519 clips, then the length of the total response is very big. The standard frame size of an Ethernet packet is 1500 bytes. I assume that V-Control thinks the Acknowledge is complete before the whole Acknowledge is received.
To solve this you need something such as a termination character or sequence. I can imagine that chr(13) is not suitable because it might be multiple times in the Acknowledge.
You need to find a single character or a sequence of characters that marks the end of the transmission and define that as TermChar.
At Configure->Options in the System Tab, there is also a “Maximum Channel Buffer Size” value, set to 600 by default. If the length of the Acknowledge exceeds this size, then the Acknowledge will be dropped. So you might need to increase this value.September 25, 2019 at 14:25 #8510
Thank you Dierk. I will increase the Maximum Channel Buffer Size. And, forgive my lack of VB knowledge, but could you explain to me how to set a TermChar?
AlexSeptember 25, 2019 at 14:39 #8511DierkParticipant
Oh sorry, with TermChar I mean a termination Character, but this is not the terminology used in V-Control. In V-Control this means the “Ack in Hex” field. In this field you have to enter one or more hex values that determine the end of the acknowledge.October 4, 2019 at 18:19 #8728
Thanks for clearing that up for me. This has been a great exercise in Basic. I an now using a different playback server that only has 84 clips on it. The CountFields operation is now consistently giving me the correct count. The only issue I am having is that the For…Next loop does not seem to be working. Below is my code. I added the ShowMessage in order to monitor the output of CountFields. Please let me know if you see anything that I am missing in order for this to work. Thanks again for your help.
dim tmp, rcv, count as string
dim i as integer
rcv = GetDeviceVar(“Received”)
For i = 1 to CountFields(rcv,”</ClipID>&h0D&h0A</clipid>&h0D&h0A</reply>”) -1
tmp = NthField(rcv,”</ClipID>”,1)
tmp = replaceAllB(tmp,”<ClipID>”,”:”)
tmp = NthField(tmp,”:”,2) + “;”
count = Str(i)
ShowMessage(” ” + count)
NextOctober 4, 2019 at 18:28 #8729
I just read what I wrote an realized I needed to elaborate a little more. By the For….Next loop not working , I mean that the code inside the loop works, but I only get the first clip name instead of all 84 clips. So to me it seems that the code is not looping but just running once.
- You must be logged in to reply to this topic.