Help with XML in variable please.

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

drolaz
Posts: 17
Joined: Fri Jan 18, 2013 7:10 pm

Help with XML in variable please.

Post by drolaz » Thu May 09, 2013 7:22 pm

Hello Group,
I am trying to send fixed XML/CGI to a webcam but am having no luck. I have researched the web for two days but no go.
Maybe some of you could be kind enough to point me in the right direction.

This is my HTML version which works fine:
<form action="http://10.0.27.232/cgi-bin/devconfig.cgi" method="post">
<input type="hidden" name="xmlMessage" value='<?xmlversion="1.0"?><DeviceRequest><Action>GET</Action><Authenticate><Username>admin</Username><Password>password</Password></Authenticate></DeviceRequest>'/>
<input type="submit" value="Send Get DeviceConfig XML" />
</form>

So in its basic form I want to do this:
on mouseUp
put "<?xmlversion="1.0"?><DeviceRequest><Action>GET</Action><Authenticate><Username>admin</Username><Password>password</Password></Authenticate>
</DeviceRequest>" into StartProcess
Post StartProcess to URL "http://10.0.27.193/cgi-bin/devconfig.cgi"
put it into tFormResults
end mouseUp

But my device responds with incorrect XML data.

Now from research it seems that my <> and "" are getting wrecked, what would be the easiest (least amount of lines) to push this variable with the data in-tacked?
Reason being is once this one works I have a ton of other buttons to add.

I have tried:
set the htmltext of tFormResults to uniDecode( uniEncode( tFormResults, "UTF8" ) )
but hat is just kicking errors.

Thanks ahead of time for any help.
Al

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Help with XML in variable please.

Post by Mark » Thu May 09, 2013 10:41 pm

Hi,

The server doesn't understand which parameter you are sending the data for and the URL is not urlEncoded. You need this:

Code: Select all

put "xmlMessage=" & urlEncode("<?xmlversion=" & quote &"1.0" & quote & "?><DeviceRequest><Action>GET</Action>" & \
"<Authenticate><Username>admin</Username><Password>password</Password></Authenticate>" & \
"</DeviceRequest>") into StartProcess
I don't know if this will make it work, but it solves at least two problems.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

drolaz
Posts: 17
Joined: Fri Jan 18, 2013 7:10 pm

Re: Help with XML in variable please.

Post by drolaz » Fri May 10, 2013 8:05 pm

Mark,
Worked like a charm!
Your the best thank you!
Al

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Help with XML in variable please.

Post by Simon » Fri May 10, 2013 8:20 pm

I'm going to post a tool I made here because I think it helps with converting to "& quote &":
infamous_quotes.zip
LC 6
(838 Bytes) Downloaded 178 times
It's just a simple tool to replace quotes and line breaks.
Hope it's self explanatory.

Oh, and nothing about urlEncode in it.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

drolaz
Posts: 17
Joined: Fri Jan 18, 2013 7:10 pm

Re: Help with XML in variable please.

Post by drolaz » Tue May 14, 2013 4:33 pm

Mark and Simon,
A new issue has a appeared and I am scratching my head as I have used this in other builds.

The below works fine:
Post TwoZoom to URL "http://192.168.1.5/cgi-bin/devconfig.cgi"

but if I try to:

Post TwoZoom to URL "http://[[IpAddress]]/cgi-bin/devconfig.cgi"

I get no results....
As before thank you in advance for any help.

Mouseup below that works..
------------------------------------------

on mouseUp
put field "ipaddress" into IpAddress

put "xmlMessage=" & urlEncode("<?xmlversion=" & quote &"1.0" & quote & "?><DeviceRequest><Action>SETFOCUSMODE</Action>" & \
"<Authenticate><Username>admin</Username><Password>password</Password></Authenticate>" & \
"<Mode>THREE_ZOOM</Mode></DeviceRequest>") into TwoZoom

Post TwoZoom to URL "http://192.168.1.5/cgi-bin/devconfig.cgi"

put it into tFormResults
end mouseUp

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Help with XML in variable please.

Post by Mark » Tue May 14, 2013 4:57 pm

Hi,

Could you tell more about what you're trying to do? Why would you write something like [[IpAdressess]]?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

drolaz
Posts: 17
Joined: Fri Jan 18, 2013 7:10 pm

Re: Help with XML in variable please.

Post by drolaz » Tue May 14, 2013 5:04 pm

The "IpAddress" is the Ip address manually added to a field by the user.

The XML that is to be sent works on multiple devices (cameras my company makes).

This app will be sending this data to different devices based on the address entered by the user.

I will have multiple buttons with different functions based on the same mouseup shown earlier.

Did that help?

Al

drolaz
Posts: 17
Joined: Fri Jan 18, 2013 7:10 pm

Re: Help with XML in variable please.

Post by drolaz » Tue May 14, 2013 5:05 pm

I have used this before and it worked:

on mouseUp
put field "ipaddress" into IpAddress
#answer "Video feed will begin shortly..Press OK to continue.."
put field "ipaddress" into IpAddress
put "rtsp://[[IpAddress]]:8554/main" into MainPath
launch merge (MainPath) with "c:/ff/bin/ffplay.exe"
end mouseUp

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Help with XML in variable please.

Post by Mark » Tue May 14, 2013 5:13 pm

Hi,

It looks like your syntax should be

Code: Select all

Post TwoZoom to URL merge("http://[[IpAddress]]/cgi-bin/devconfig.cgi")
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

drolaz
Posts: 17
Joined: Fri Jan 18, 2013 7:10 pm

Re: Help with XML in variable please.

Post by drolaz » Tue May 14, 2013 5:56 pm

Bummer....
Didn't work any other thoughts?
Im still trying different variations...

Thanks
Al

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Help with XML in variable please.

Post by Mark » Tue May 14, 2013 6:24 pm

Hi Al,

Could you post the entire script up to the line containing the merge function?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

drolaz
Posts: 17
Joined: Fri Jan 18, 2013 7:10 pm

Re: Help with XML in variable please.

Post by drolaz » Tue May 14, 2013 6:36 pm

Below is the original working version, below that is the variation you suggested:

on mouseUp

put field "ipaddy" into IpAddress

put "xmlMessage=" & urlEncode("<?xmlversion=" & quote &"1.0" & quote & "?><DeviceRequest><Action>SETFOCUSMODE</Action>" & \
"<Authenticate><Username>admin</Username><Password>password</Password></Authenticate>" & \
"<Mode>THREE_ZOOM</Mode></DeviceRequest>") into ThreeZoom

Post ThreeZoom to URL "http://192.168.1.5/cgi-bin/devconfig.cgi"

put it into tFormResults

end mouseUp

as suggested but not responding:

on mouseUp

put field "ipaddy" into IpAddress

put "xmlMessage=" & urlEncode("<?xmlversion=" & quote &"1.0" & quote & "?><DeviceRequest><Action>SETFOCUSMODE</Action>" & \
"<Authenticate><Username>admin</Username><Password>password</Password></Authenticate>" & \
"<Mode>THREE_ZOOM</Mode></DeviceRequest>") into ThreeZoom

Post ThreeZoom to URL merge("http://[[IpAddress]]/cgi-bin/devconfig.cgi")

put it into tFormResults

end mouseUp

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Help with XML in variable please.

Post by Mark » Tue May 14, 2013 6:54 pm

Hi,

What happens if you execute this script?

Code: Select all

on mouseUp
   put field "ipaddy" into IpAddress
   put "xmlMessage=" & urlEncode("<?xmlversion=" & quote &"1.0" & quote & "?><DeviceRequest><Action>SETFOCUSMODE</Action>" & \
         "<Authenticate><Username>admin</Username><Password>password</Password></Authenticate>" & \
         "<Mode>THREE_ZOOM</Mode></DeviceRequest>") into ThreeZoom
   put merge("http://[[IpAddress]]/cgi-bin/devconfig.cgi") into myUrl
   post ThreeZoom to URL myUrl
   put the result into rslt
   if rslt is empty then
      put it into tFormResults
   else
      beep
      answer error rslt
   end if
end mouseUp
Do you get an error message?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

drolaz
Posts: 17
Joined: Fri Jan 18, 2013 7:10 pm

Re: Help with XML in variable please.

Post by drolaz » Tue May 14, 2013 7:06 pm

It reports back "invalid host Address"
but if i swap the [[IpAddress]] in the merge line with the actual address it works.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Help with XML in variable please.

Post by Mark » Tue May 14, 2013 7:12 pm

Hi,

What happens if you don't use the field but replace the first line with something like

Code: Select all

   put field "123.45.67.89" into IpAddress
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply