Sunday, December 13, 2015

Saving file from image proxy

Image proxy is a web page used to serve images from web sites that stores its images outside of the root directory of the web page. This is done for security purposes. The web image tag looks something like <img src=imageproxy.php?filename=xx.png>

The resultant web page looks exactly like any web pages except when you try to save it. The file name become imageproxy.php instead of xx.png. Any user will complain that this is no user friendly.

I took hint from some Netizens that by using the ALT attribute and put the actual filename as its value solved the issue. It also helps when the image is not available. User will get to save the file with the proper name. It benefits both the programmer and user.



Saturday, December 12, 2015

Chek Jawa

Chek Jawa is a place name in Pulau Ubin. Previously it is just a wetland that is not accessible to public. In 7 July 2007 NParks make it into a visitor accessible park. This trip is specifically to visit Chek Jawa Wetland.

To access the island, you have to go to the Jetty. It is just further down the food center in Changi Village.



The access to the jetty is via a building (circled in the picture). You have to go downstairs to the basement. There are two areas. One for Ubin and the other one for Pengeleh Malaysia. The ubin access is on the right hand side. There is no passport needed for Ubin access.

If there are not many people, you will have to wait at the waiting area. Twelve persons are required for the bump boat to begin the trip. You can hire the whole boat if you want. The trip is $3 one way per person. I don't know the price increased already as I read from blogs that it is only $2.50. No discount for kids and seniors. The trip itself is about 15 minutes. Its school holiday so I just need 5 minutes wait before embarking the boat.

I have planned a very indirect way of going to Chek Jawa. First detour is to the Sensory Trail.

The first picture I took is not yet identified. Its bud or fruit looks red.



Turning into Sensory Trail, there is yet a vine that I cannot identify.



Here is a moth that it not identified even though I post it on web for ID. It is a day flying moth.


The first identifiable picture is just a common grasshopper.


The next one is a butterfly that hides below leaves. Its probably a Common Awl.


Further down, I saw a vine from the Bean family but can't identify it.


Common Sailor are seen quite often, this one stays for a shot.


The last picture from Sensory Trail is a creeper. The tiny bean family plant is a Desmonium. Its full common name is Greater Clover-Leaved Desmonium. Sure sounds big even when it is tiny.


Turning into Jalan Ubin which is a metalled road,  I saw a very white fungus. Its over exposed. Should have use digital camera instead of handphone.


Its hard to capture this insect as it never stops for a shot. This is a Common Mormon.


According to OpenStreeMap, there is a trail just before the junction. I missed that. I choosed the next trail at Jalan Durian just after the junction.  Turned into the trail and met with a dead end. But it is still fruitful. Saw a funny looking flower. Only found out later that it is dead one. A live one looks nicer. Not able to identify.



At the end of Jln Durian saw a cute climber. Its leaf end curls up. Again blank on ID.


Instead of going into the one way path to wetland, I choose a detour path. The first thing I noticed is a Coral Fungus. A rare sight.


A Knight rests peacefully for a focus shot. Slightly out of position due to zooming with free hand.


This common hairy plant is a Hairy Clidemia

Further down the path saw a web. That owner is a silk Orb Weaver spider.


This female Tailed Jay is quite faded but its characteristics are still visible and intact.


Ixora lobbi is very common around here. Took one picture of its blooming flower but it is blurred. Settle for buds instead.


A family of wild boar walked right behind me across the path. I could only stood still and took a number of pictures. Only this one is clear. Flash is required but I do not want to startle the wild animals. Read from Netizens that wild boars here are friendly. One of them is famous but is dead and buried. I don't want to hang around them as they are still wild.


A Malay Viscount came out and stay right in my path. I obliged to take a picture of it.


Going back into the main path, I reached Chek Jawa Wetland. The first thing that surprises me is a Shed with Cold drink dispenser. There is no electrical lines linking to the wetland. Later I found out that there is a generator further behind.

I went into the jetty through a hut. Did not bother to take a picture of the hut. There is nothing worthy of a click around here.

Walking back to the shed and proceed to the bridged walk. Its high tide and I could not see anything that is worth taking at all. From the bridge walk, there is another Mangrove bridged walk. Went into it and bring out my GPS map. It could not get the GPS location. It is here that I noticed that the GPS is not available since I visited the Jetty earlier. It is probably due to me switching to Panorama Camera app to take a parorama view of the main island.  Switched off GPS and back on and every thing goes well except that Endomondo does not capture the trail from Jetty to the Mangrove Walk. WikiLoc is working fine as it is in another handphone.

Nothing much to take picture all the way to the shed. I took a rest at the shed and some students were giving out survey sheets. I am obliged to fill in one. The young girl was surprised that I indicate no change needed. Obviously right? I am a naturalist, there is no reason to change the natural environment to artificial one.

They are surprised that a senior citizen walked 6.5 KM all the way from the main jetty. They are even more surprised that I am going to walk another 5KM. I did share Osmand and WikiLoc app to them to show how I can walk around easily.

The sky looks grumpy and thunders heard. Sadly all the insects go into hiding from then on. The rest of the route was just walking.

The outward bound route is also a one way route. Not surprising that there are cyclists who go the wrong way. After reaching Jln San Heng, I proceed North as planned even though it drizzles slightly now.

At the end of Jln San Heng, there is a beach. It is supposed to be a camping site. Surprised to see some barrier on the sea. I though it is kelong pikes but on the map it showed that the barrier stretches for miles along the coast. Don't know what is that for.

The return trip is supposed to go via a trail. It was closed. No choice but to take another trail further down the road. It is like a kampong trail that passes through a few houses. Again nothing interesting here.

After reaching Jln Ubin, saw from the map that there is another trail that leads to another wetland. Ventured into it and is disappointed that it is a dead end with construction in progress. On the way in heard a buzzling sound. It is a large group of bees moving house. I walked right pass it only to realize it after that. Luckily nothing happens and no sting received as a gift.

Turned into Jalan Batu Ubin instead of continuing through Jln Ubin as planned. There is nothing here worth taking pictures either. Reached the village and realized that they only sell seafood. Time to go back to main island.

Walked to the jetty and found that they are short of just one person. No waiting time to embark on to the bump boat. One thing I don't like embarking here. We have to walk through a number of other bump boats. It is a reason why I hesitate to bring handicapped people to Ubin.

The trip ended with late lunch in the food court.

The picasa album is here.

WikiLoc route map is here.




Tuesday, October 13, 2015

What technology that helps the blind

Ten years ago, I evaluated a number of technologies that is of use to visually handicapped (VH). It was quite a fruitless search. Ten years later I attended the China Information Accessibility Forum in Beijing and it showed quite a number of improvement. The following is a description of some of the technologies available as gathered from the forum.

I am not a fan of Apple iPhone but I do admire the free VoiceOver accessibility feature available. With it, VH can use the phone almost as easily as others.  There were apps written to help blinds. Ariande can help blind navigate places alone. LookTell Money reader can read money denominations (only US$). Color ID Free can read colors (can only read simple color). VizWiz provides human assistance to help VH. Android has assistive technology also but is a far fetch from VoiceOver.

Another technology by Apple is also of interest. It is the iBeacon technology. This technology allows a BT beacon to beam its proximity and some static information to the user. Obviously, user must use iPhone to do it. (Android have apps that can do it too.) It has a number of applications for VH. If every bus could be equipped with such beacon, it would help VH to detect which bus is the required one.

If the beacon can be fixed on every bus stop then VH will know which one to disembark on the last announced stop. If a building is equipped with Beacon, It will greatly help VH or sighted to know their exact location with a given virtual map of the building. Even those sighted can get lost in a very large shopping mall. Android has yet to catch up on this. Samsung is reportedly following suit but I am yet to see it.

Voice dictation system. Microsoft demonstrated its Cortana system that integrates voice recognition with linkage to app activation - a sort of personal assistance. Although it failed several times to perform during the presentation, it nevertheless a good technology to adapt for the blind. I have not seen Apple Siri at work but it is basically implemented much earlier than Microsoft. Android does not have one but there are quite a number of apps that does the same. How good is it is yet to be ascertained.

Obstacle Avoidance and Detection system. This technology was not that new but has not been very successful. Saw a video on this system. It could be helpful but as far as I know, detecting suspended small/pointed objects is still an issue.

Object location tag. Saw from booths in the forum that allows items to be tagged with a tag that has a buzzer built in. You could call up to 8 devices per calling device. It is nothing new just that the idea is rather interesting. If they could make it into adhesive tag then its use might be wider. I would like to see something like a RFID. It uses passive tags. The reader must be able to pinpoint the tag among other tags.

Face recognition and detection. According to the demonstrator, it helps the blind to be able to talk to others face-to-face by detecting where is the person. It allows pre-recorded face so that it can even announce the person's name. It did recognize me as a 50 plus old anonymous guy.

Small MP3 like equipment that can play music and read documents (without screen) is something of interest. A number of companies were making it. I would be more interested if it can automatically change language according to the mixed language document.

PC screen reader. It has been ages since this technology is available. Nothing much changed. Laptops and PC sales are going down due to increasing mobile handphone use. It is sunset technology.

Some researcher was trying to integrate all the technologies in one app. It might be useful but probably takes decades to do so.

One biggest challenge is to make the equipment affordable. Many of the VH have low or no income. Having such equipments are next to impossible. Don't forget many of the equipment requires internet access. There is a monthly bill to pay. Many equipments also require general public to take part like iBeacon for buildings/bus. The infrastructure cost is huge. Other VH are also illiterate. Coaxing, educating them enough to use such equipments is a long and tedious task.





Sunday, September 13, 2015

Passing parameters to Filemaker Script

Filemaker only accept one parameter when you "perform script". There are many suggestions to pass more than one parameters. Some use custom functions. One of the most noted function is #Parameters. It stores name and value set into a dictionary. Others suggest using "List".

For those who do not use Filemaker advanced, there is no way to create custom functions. For list, if you just pass it a list of values separated by "carriage return". The only problem is that if you passed a blank value, the next value will be used instead. This caused considerable inconveniences.

Some others passes a XML or JSON as parameter and it requires a function to do the extraction. I guess this is the best way to do it. The following is an example of getting the variable value by creating a XML, stored as global value and call the script with node name as parameter.

# Construct a xml for all the variable and values. Store as global variable $$xml
# The passed xml must not contain carriage return just join all the nodes end to end
# The xml constructed must also be escaped to make it valid.
Set Variable [ $pkey ; Value: Get(ScriptParameter) ] 
Set Variable [ $$xml ; Value: Substitute ( $$xml ; "><" ; ">"  & ¦ & "<" ) ] 
Set Variable [ $ccount ; Value: 1 ] 
Set Variable [ $pcount ; Value: PatternCount ( $$xml ; ¦ ) ] 
Set Variable [ $pvalue ; Value: "" ] 
Loop
 Exit Loop If [ $ccount > $pcount ] 
 Set Variable [ $xsearch ; Value: GetValue($$xml;$ccount) ] 
 Show Custom Dialog [ "test" ; $xsearch ] 
 If [ PatternCount ( $xsearch ; "<" & $pkey & ">" ) =1 ] 
  Set Variable [ $pvalue ; Value: Let ( [ $p = Substitute ( $xsearch ; "<" & $pkey & ">" ; "" ) ; $p = Substitute ( $p ; "</" & $pkey &">" ; "" )] ; $p ) ] 
  Set Variable [ $ccount ; Value: $pcount ] 
 End If
 Set Variable [ $ccount ; Value: $ccount+1 ] 
End Loop
Exit Script [ Result: $pvalue ] 

Note that the | symbol is actually the Filemaker "carriage return" sign.

Recent development see another way of passing parameters. This is done by using JSON. Filemaker has added functionalities to read/write the elements of JSON. It makes passing parameters much easier with much less hassles.





Friday, September 11, 2015

Filemaker example of Xpath

Previously I talked about using Filemaker to extracting xml node text without using plugins. I have created a working script that does just that. You just need to call the first script that does a "Tidy". The script will remove unnecessary carriage return, tabs and extra spaces between nodes. It also add carriage return after every node. You can get the node text value by adding the xpath path with a carriage return in front of the xml as one parameter to the second script.

The reason for putting them in two script is that you only need to "Tidy" the xml once but you need execute  the second script a number of times to extract multiple node values.

The first script is called "xtidy". The script is as follows

Set Variable [ $xml ; Value: Get(ScriptParameter) ] 
Set Variable [ $xlen ; Value: Length ( $xml ) ] 
Set Variable [ $ccount ; Value: 1 ] 
Set Variable [ $xout ; Value: "" ] 
Set Variable [ $xfound ; Value: 0 ] 
Set Variable [ $xtext ; Value: "" ] 
Loop
 Exit Loop If [ $ccount > $xlen ] 
 Set Variable [ $xsearch ; Value: Middle ( $xml ; $ccount ; 1) ] 
 If [ $xsearch = ">" ] 
  Set Variable [ $xfound ; Value: 1 ] 
  Set Variable [ $xout ; Value: $xout & $xsearch ] 
 Else If [ $xsearch = "<" ] 
  Set Variable [ $xtext ; Value: Substitute ( $xtext ; Char ( 13 ) ; "" ) ] 
  Set Variable [ $xtext ; Value: Substitute ( $xtext ; Char ( 11 ) ; "" ) ] 
  Set Variable [ $xtext ; Value: Trim ( $xtext ) ] 
  Set Variable [ $xout ; Value: $xout & $xtext & "<" ] 
  Set Variable [ $xtext ; Value: "" ] 
  Set Variable [ $xfound ; Value: 0 ] 
 Else If [ $xfound = 1 ] 
  Set Variable [ $xtext ; Value: $xtext & $xsearch ] 
 Else
  Set Variable [ $xout ; Value: $xout & $xsearch ] 
 End If
 Set Variable [ $ccount ; Value: $ccount+1 ] 
End Loop
Set Variable [ $xout ; Value: Substitute ( $xout ; "><" ; ">" & ¦ & "<" ) ] 
Exit Script [ Result: $xout ] 
The second script is call "Xpath". The script is as follows



# Just add the path with a carriage return to the xml like $xpath & $xml as parameter
Set Variable [ $xml ; Value: Get(ScriptParameter) ] 
Set Variable [ $xmlcount ; Value: PatternCount ( $xml ; ¦ ) ] 
Set Variable [ $xpath ; Value: GetValue($xml;1) ] 
Set Variable [ $xpath ; Value: Substitute ( $xpath ; "//" ; "" ) ] 
Set Variable [ $xcount ; Value: PatternCount ( $xpath ; "/" )+1 ] 
Set Variable [ $xpath ; Value: Substitute ( $xpath ; "/" ; ¦ ) ] 
Set Variable [ $pathLevelCount ; Value: 0 ] 
Set Variable [ $pathRepeatCount ; Value: 0 ] 
Set Variable [ $lastXsearch ; Value: "" ] 
Set Variable [ $lastXsearchCount ; Value: 0 ] 
Set Variable [ $xmlresult ; Value: "" ] 
Set Variable [ $xcurPath ; Value: "/" ] 
Set Variable [ $xlevel ; Value: 0 ] 
Set Variable [ $xlevelCurrent ; Value: 0 ] 
Set Variable [ $ccount ; Value: 1 ] 
Set Variable [ $xml ; Value: Middle ( $xml ; Position ( Upper ($xml) ; "" ; 1 ; 1 )+15 ; Position ( Upper($xml) ; "" ; 1 ; 1 )-Position ( Upper($xml) ; "" ; 1 ; 1 )-15 ) ] 
Set Variable [ $xmlcount ; Value: PatternCount ( $xml ; ¦ ) ] 
# Script to find lowest level of the first search path
Loop
 Exit Loop If [ $ccount > $xmlcount ] 
 Set Variable [ $xsearch ; Value: GetValue($xml;$ccount) ] 
 If [ Left ( $xsearch ; 2 ) = "</" ] 
  Set Variable [ $xlevelCurrent ; Value: $xlevelCurrent-1 ] 
 Else If [ PatternCount ( $xsearch ; "<" ) = 1 ] 
  Set Variable [ $xlevelCurrent ; Value: $xlevelCurrent+1 ] 
 End If
 Set Variable [ $xnode ; Value: Middle ( $xsearch ; 2 ; Position ( $xsearch ; ">" ; 1 ; 1 )-2) ] 
 If [ PatternCount ($xnode;"/")  ­ 0 ] 
  Set Variable [ $xnode ; Value: ¦ & ¦ & ¦ & ¦ ] 
 End If
 If [ Position ( GetValue($xpath;1) ; $xnode ; 1 ; 1 )  > 0 ] 
  If [ $xlevel = 0 ] 
   Set Variable [ $xlevel ; Value: $xlevelCurrent ] 
  Else If [ $xlevel > $xlevelCurrent ] 
   Set Variable [ $xlevel ; Value: $xlevelCurrent ] 
  End If
 End If
 Set Variable [ $ccount ; Value: $ccount + 1 ] 
End Loop
Set Variable [ $xlevelCurrent ; Value: 0 ] 
Set Variable [ $ccount ; Value: 1 ] 
Loop
 Exit Loop If [ $ccount > $xmlcount ] 
 Set Variable [ $xsearch ; Value: GetValue($xml;$ccount) ] 
 If [ Left ( $xsearch ; 2 ) = "</" ] 
  Set Variable [ $xlevelCurrent ; Value: $xlevelCurrent-1 ] 
 Else If [ PatternCount ( $xsearch ; "<" ) = 1 ] 
  Set Variable [ $xlevelCurrent ; Value: $xlevelCurrent+1 ] 
 End If
 # Look for path start
 Set Variable [ $xpathtxt ; Value: GetValue($xpath;$pathLevelCount+1) ] 
 If [ Position ( $xpathtxt ; "[" ; 1 ; 1 )  ­ 0 ] 
  Set Variable [ $xpathary ; Value: Substitute ( $xpathtxt ; "[" ; ¦ ) ] 
  Set Variable [ $xtxt ; Value: GetValue($xpathary;1) ] 
  Set Variable [ $ycount ; Value: GetAsNumber ( GetValue ( $xpathary ; 2 ) ) ] 
 Else
  Set Variable [ $xtxt ; Value: $xpathtxt ] 
  Set Variable [ $ycount ; Value: 1 ] 
 End If
 # Look for path end
 Exit Loop If [ Position ( $xsearch ; $lastXsearch ; 1 ; 1 ) = 1 ] 
 If [ Position ( $xsearch ; "<" & $xtxt & ">" ; 1 ; 1 ) = 1 and $xlevelCurrent = $xlevel+$pathLevelCoiunt ] 
  Set Variable [ $pathRepeatCount ; Value: $pathRepeatCount+1 ] 
  If [ $pathRepeatCount=$ycount and $pathLevelCount  < $xcount ] 
   Set Variable [ $pathLevelCount ; Value: $pathLevelCount+1 ] 
   Set Variable [ $lastXsearch ; Value: "</" & $xsearch & ">" ] 
  End If
  If [ $pathLevelCount = $xcount and $pathRepeatCount = $ycount ] 
   Set Variable [ $xmlresult ; Value: Middle ( $xsearch ; Position ( $xsearch ; ">" ; 1 ; 1 )+1 ; Position ( $xsearch ; "<" ; 1 ; 2 )-Position ( $xsearch ; ">" ; 1 ; 1 )-1 ) ] 
   Set Variable [ $ccount ; Value: 50 ] 
  End If
  If [ $pathRepeatCount=$ycount and $pathLevelCount < $xcount ] 
   Set Variable [ $pathRepeatCount ; Value: 0 ] 
   Set Variable [ $lastXsearch ; Value: "</" & $xtxt & ">" ] 
  End If
 End If
 Set Variable [ $ccount ; Value: $ccount + 1 ] 
End Loop
Exit Script [ Result: $xmlresult ] 



Wednesday, September 09, 2015

How to read XML nodes if you don't have XML parser?

I used Filemaker to create database applications. On of the application need to access to Web Services. The returned text is XML. Therefore, I use a plugin called BaseElements to read the nodes. However, recent development requires the same functionality to be available in iPad. Filemaker for iPad does not allow plugins.

Fortunately, the xml parser is not a general parser that translates XML to an array. It just returns the text value of the node defined by the path.

To circumvent the issue, I decided to replicate the same functionality of the BaseElement plugin (BE_XPath() function). The function works like this. You pass it a XML and a path and it returns you the result. For exmaple, BE_XPath($xml;"//Data/myname") will return you the text value from the path. If there are more than one "Data" then you need to define it as a sort of array like Data[1].

It is not at all difficult to interpret the xml. There is just one step to do before parsing it. You need to add [Carriage Return] after every node. Usually the xml is returned as a continuous text without a carriage return character. What I need to do is just search for "><" and replace it with ">[CR]<". [CR] is the character code 13.

The result of doing such replacements means each node will be on a line ending with a carriage return. For example,

<myname>xxx</myname><myphone>yyy</myphone>

will be come

<myname>xxx</myname>
<myphone>yyy</myphone>

What you need to do is search for the path in the sequence for each line of the XML. My example uses Data and myname. So I just read each line and look for first. If it is found then I look for . If reaches first then is not found. If the line returns "" before the two nodes are found then the path is not available.

If the path is Data[x], I just need to repeat the search for till the x occurrence is reached. It is as simple as that.

Once the node name is found, it is time to remove the xml node name. Well, it is quite simple. You simply replace the enclosing node names together with its XML markup as "". Don't worry as XML does not allow "<" and ">" to be part of node text.

Obviously, you need to look out for <myname/>. This means that the node exists but no value. But since I am looking for the node text, whether it exists or have no value is not an issue, I just return a blank unless it is specifically required to determine whether the node actually exists.

The above is assuming that the XML is without carriage returns, tabs and spaces. If the xml is generated by hand and is "tidied". the situation more complicated. You will need to reformat the xml to remove all the carriage return, linefeed, and leading and trailing spaces first then proceed to add carriage return as per described above.




What is the difference between SOAP and POX on Web Services

My previous two blog talks about two aspects of Web Services. What is the differences between the two methods. To make it simple, it is basically the same except that one is easier and the other is harder. They both return exactly the same result.

Let's talk about the easier one. Using SOAP is by far the easiest way. You just need to compose an array according to the documentation available for the Web Services and send to a function of the WS object.

The harder one is to compose the XML envelop then add the nodes to make a complete XML document and then send it.

How did the Web Services work with two different methods? Actually they are both the same except that the XML is posted to the second stage. Allow me to explain the process.

When we use SOAP, we creates a connection to the Web Services (henceforth WS). We then called the particular function via the connection object and pass it an array of parameters. In PHP the script is as follows.

$client= new SoapClient("http://webservices_address", $opt);
$param=array('action'=>'theaction');
$test=$client->thefunction($param);
echo $test->functionresponse->result;

Now if the arguments is a multiple array type the $param will be something like this

$param=array('action'=>array('subaction'=>subtheaction'))

You have to know what function to call and what parameter to pass. Normally this is found in WS documentations. Now, it is very important to be specific about the object name of the array. It is often case sensitive. "subaction" is not the same as "subAction". Often WS will simply tells you that a parameter is missing because of case differences.

To a user, the PHP script is all that is needed to get it working. In actual fact PHP works in the back ground and actually posts the data in a different form. You guess it right. It actually posts a XML to WS after composing it from the WSDL that it first addressed to. This means that it actually interprets the returned value when it first posts to WS, compose the XML based on the definition then sends the XML to another address (usually a sub address of the original) according to the definition.

Our second method actually composes the XML directly and posts to the sub address. It is therefore the same thing except you need to compose the XML the hard way unless you download the WSDL of the WS and do a transpose yourself.

How does the multiple array looks in XML? It is exactly the same except in different format.

subtheaction

Obviously, the PHP array is much easier to read. Now, you would say why not just use SOAP since it is much easier? Yes it is unless the application you use does not have SOAP functionality. PHP have both SOAP and CURL (which provide POX functionality by sending the XML as post). If I use PHP I would prefer to use SOAP instead of CURL. What if you use an application for your business but that application only have CURL?

Since CURL can post a XML to the WS and still gets back the same result, it is pretty alright to use it to access WS. It will be more difficult as you will need to understand what to do when composing the entire XML. Some WS does provide the XML information and allows POX.

Filemaker is a good application for a small business. It is very easy to create a complete database application without much technical knowledge. To access to WS, there is no choice but to use CURL. It might be harder but it will still work.

Actually Filemaker can post to a web site and gets the result but then it has to call a PHP script, pass the information to it and it in turn calls WS, get the result and return it to Filemaker. It is pretty round the world way but it still works.

Post note. SOAP communication has been discontinued. The only way is to use POX now.




Sunday, August 30, 2015

How to Access Web Services using SOAP

Previously I mentioned about accessing Web Services in Communicating with Apple Web Services. It communicates directly with the Web Services by posting a XML to it.

My previous post talks about using Filemaker to access the Web Services. Actually you can use a browser to access it. In actual fact, using browser is the more common methods of accessing Web Services. Most browser has Javascript facility. Javascript has a function called XMLHttpRequest that can access web services. This method is usually called AJAX (Asynchronous Javascript And XML). Using this method, you still send the XML to the Web Services.

It is no joke composing the XML. There is an easier way to access Web Services if you have a web site that runs on PHP. PHP has a module that provides SOAP (Simple Object Access Protocol). What you need to do is to call the function and pass it an array of the parameters.

Generally you need to tell the Web Services what to do with the data. But how to know what to send? Well, it is quite simple. Web services usually uses a language called WSDL (Web Services Definition Language.) If you use a web browser and call the address directly like a web page, it actually returns you a XML telling you what functionality it has and what parameters to provide.

Below is a simple PHP program to communicate with a Web Services. It calls a function called "thefunction" and passes a parameter called $param. It echoes a node name called "result" in the returned XML.

$opt= array('encoding'=>'UTF-8');
$client= new SoapClient("http://webservices_address", $opt);
$param=array('action'=>'theaction');
$test=$client->thefunction($param);
echo $test->functionresponse->result;

Nested parameters can be done by adding arrays in an array like below

array('higherlevel'=>array('lowerlevel'=>'xxx','lowerlevel2=>'yyy'))

Note that php actually parses the returned xml automatically into an object array. You need to use the object reference method to access individual values. Converting the object to other form is beyond the scope of this blog.

There are some Web Services that require client cert. This can be easily done by adding "'local_cert=>'certname.pem'" to the variable $opt. The cert and key must be in the same file.






Saturday, July 04, 2015

A case of two cyclist again

Was cycling on Upper Thomson Road towards the East. This cyclist on a MTB was cycling on foot path. I am cycling on the road. I am travelling at 28-30KPH. Overtook him after SLE. Did not notice till I slowed down at a slope. He was trying to catch up.

He was on a MTB and on footpath. I was on a hybrid and is on road. There is no way he could catch up as it is impossible to go fast on footpaths. Unlike the previous case, I have no hindrances to slow me down. He has plenty. Anyhow, he could not play tag with me as I am simply too fast.

There is only one instance where he actually catches up. After I am aware of his efforts. I simply keep at 30KPH and he could not even be seen. He finally managed to catch up when I stopped at traffic lights at Yio Chu Kang Rd. I don't know whether he turned off or stopped after that. As it is down slopes after the junction, I go easily at 32-36KPH till Ang Mo Kio Ave 1 where I slow down and turned into it.

Cycling on footpath at over 20KPH in the early morning is dangerous as the footpath is not designed for cycling and visibility is poor. Even cycling on PCN has its many dangers already. I do not want to encourage him to speed so I make it impossible for him to catch up rather than allow him to play tag with me at my my usual slower pace.



Saturday, June 20, 2015

A Case of two Cyclists on PCN

The scene started at the junction of Hougang Ave 7 and Tampines Rd. I stopped at the road junction. This guy with a Dahon came up besides me. The first thing he looked at is my bike. Well, nothing to look at. I am having a cheapo bike.

At the start of the Serangoon PC, he starts to overtake me. Looking at the speed he is going, he probably travel at well above 25KPH. Since the PC is quite empty, I start to give chase. After a while I caught up with him and noticed that he travels at 30KPH.

It is not normal I go at the same speed when there are other users on the road so I slowed down whenever there are pedestrians along the way then speed up to catch up.

He is keenly aware of my presence and keeps looking back at me when I am very near him. Interestingly, he did not try to shake me off. I never have intention to overtake so I just keep a short distance behind him. So we keep playing tag on and off till Ponggol way via PPN PC.

I had to stop at the street crossing for safety reason. He just crossed it without even pausing. On Serangoon Way, he did the same. Since I am going onto Serangoon Way, I do not intend to keep up again. We parted way from there.

He is young and on a branded fast bike. I am old with a average hybrid bike and a bag of tools. There is no way I could overtake him and keep it that way. It is simply too dangerous to race on a PC. I just want to see what he can do with a nice bike like that since he have an "atas" look when he first encounters me.



Wednesday, June 10, 2015

Insects mimicking Preditors

Often you see pictures of insects or animals that looks like predators. They have big spots that looked like eyes, shape of snake, etc. Do they intentionally  evolved to look like one?

My hypothesis is like this. In the process of evolution, the specie have developed with features that resembles predators. Since other animals are afraid of predators, their chance of survival gets better thus they multiply.

As evolution goes, it developed further and those that by chance enhances the feature get better chance of survival and passed down the gene.

Through many generations, the selective survival of those who evolved towards predatory look makes the animal looked more like the predator and today we see the result of the survived specie.

The evolution theory of "survivor of the fittest" does not means that only the strong survived. It actually means that the specie is able to survive by their strength, ability, features or properties. It is the ability to avoid being eliminated.



Monday, May 25, 2015

Setting and resetting Default Apps

Was playing with a map app. The map application offers to take pictures. When the option is clicked, it prompts to choose which camera app to use. Being curious, I select "always use" option and did not notice the prompt after that.

I tried to go through all the menus and settings but just could not find the setting to unset the default app. Going to the internet to search for "unset default app" for the map app does not help. It did not have anything that is related to resetting the default.

Going on a hunch, I tried looking for "Android reset default app". There are a lot of people talking about it. I hit jackpot.

Unlike windows programs where all the settings are within the program itself, Android have different ways of doing things. You can set the default app in another app but to reset it, you have to go back to "settings", "application management" and select the application to reset. Just click on the app and scroll down. You will find a "reset default" button. Choose it and the work is done.

You may ask "what about other apps which I want to keep the default camera setting". Well, you are out of luck.



Sunday, May 24, 2015

Simple Restful Web Services

I was trying to use PHP CURL library to access a web services. In the process I found a useful library that makes using CURL very easy. It is called Httpful (https://github.com/nategood/httpful). The library is useful if you don't mind the many duplicate functionality.

In the process of testing, I was wondering whether CURL actually posts the XML. Since I did not want to access any real time web services, I decided to use PHP to get the posting. Naturally it failed. The standard global variables $_POST[] does not contain any content neither does $_RESPONSE[]. I search the internet and discovered that the post is more like posting a file rather than posting a form. There is a PHP function to get this kind of content.

After successfully retrieving the content, I was wondering whether I can make this functionality work like a very simple restful web services. I began to write a proper PHP page to simulate the web service. The following are the scripts for posting and the restful web services page. The XML request and response are dummy values which is stored as a simple variable, It is not in the scope of this blog to show how to create XML in PHP.

The posting page :-

include "httpful.phar";
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
$url="http://localhost/sampleresponse.php";
$authenticate = "jonathan@mail.commypassword";

$response = \Httpful\Request::Post($url)
    ->body($authenticate)
    ->mime("XML")
    ->autoParse(false)
    ->expectsType("XML")
    ->send();
$xml= new SimpleXMLElement($response);
$sessionid=$xml->xpath("//userSessionId")[0];
if ($sessionid==""){
    die("Error User does not exist or password is wrong.");
}

The restful response :-

include "httpful.phar";
$postText = file_get_contents('php://input');
$xml= new SimpleXMLElement($postText);
$auth=$xml->xpath("//AuthenticateRequest")[0];
if ($auth){
$user=$xml->xpath("//userId")[0];
.
.
.
if ($verified) {
    die("
             Sdt7tXp2XytTEVwHBeDx6lHTXI3w9s+M
       
");}};

Well, it is simple straightforward PHP turned into restful web services. Obviously CURL could post user credentials itself while posting the request. This is a simple example.

Not everyone have a web server. In the case of user just want to access the restful web services via the browser, they could simply write a Javascript AJAX function to do the posting. There are plenty of examples in the internet that shows you how to do posting in AJAX. It will not show it here.

For more security, it is best to use HTTPS for the web services.



Sunday, May 03, 2015

Traffic Lights at Junctions

Recently there is a discussion on Facebook Group on the above subject. The discussion is quite extensive. I will give an account on the facts discuss and add a few points not discussed.

In modern cities roads are primarily meant for cars. Pedestrian walks were added to facilitate pedestrian transports. On some old roads pedestrian still share with cars. Express ways are for the sole use by cars only.

LTA does not leave pedestrians without the means too. First, there are pedestrian crossings guided by traffic light. Many busy roads have on-request buttons so as to keep cars moving more smoothly. Minor roads does not have button control. It just switch on and off regularly.

Zebra crossings are actually pedestrian priority crossings. It is usually found near schools. Pedestrian bridges span across roads so that it will not disrupt car traffic. Similarly, underpass for pedestrians serve the same purpose.

There are a number of junctions near MRTs that are fitted with senior citizen card reader so that it will give senior citizens extra time to cross the road.

Some roads are closed at specific time just for pedestrians. It is not just during festive seasons. Some place like Holland Village have permanent time slots for this purpose.

As usual, every group are biased towards their own stand point. It is not wrong to behave this way as it will check the balance of the transportation facility based on their own interest. However, most people does not look at the standpoint of the other side.

During my study at a seminary, the Dean Dr. Roger Capps have a specific assignment for the Masters degree students. They are to take on the role of the opposition and argue from that stand point. His reason is that if the student can't even withstand his own argument against his own belief, how would he/she able to go out and face the real world. Obviously it is super tough to be in the shoe of the opposition to one's conviction. Sun Tze have this rule "知己知彼,百战百胜。" (Know yourself, know your enemy, you will always win). Its an analogy that pass the time test.

Back to our point on traffic light. It is this lesson that I learned that keeps me reminded that I should not look only on my stand point. The lesson applies to every one too. Obviously, we would want the traffic light to favor pedestrians. However, it means that cars will suffer. If you have to drive through the city, you will know how it feels to stop at every traffic light. There are lots of people earning a living driving vehicles. It is, therefore, imperative that a balance must be maintained. Although, the priority is given to cars, but there are a number of avenues where pedestrians were given due consideration. We should accept the fact that not all things will work in our favor. We complained against cars but cars also complained against us too.

LTA should not stop making life better for pedestrians too. There are other countries that favor pedestrians to cars.  LTA have to look at what is done and see if it can be implemented here too. However, just because other did it does not means that it is applicable here. Each country have their own unique setup. It works in one place does not means that it works everywhere.




Saturday, May 02, 2015

Silent Majority

In society there are a large number of people usually does not voice out or act openly. They are usually called the "Silent Majority". Their opinions are usually unknown since they do not act or voice out. It is, therefore, very difficult to find out what is their opinion on a specific issue unless a very large scale anonymous opinion poll is conducted.

Those people in the "silent majority" usually composed of the following

1. Those who just don't care.
2. Those who are indifferent to the issue.
3. Those who are against.
4. Those who are pro activity but does not want to take part.
5. Those who are afraid.
6. Those who are too timid to act.
7. Those who are too tied down/busy to act.

When one stands out and say he/she speaks for the "silent majority", The implication is that he/she is speaking on behalf of "all" of them. It is actually true only for those who are agreeable to the action but do not act. He/she cannot claim to speak on behalf of all "silent majority". Since they are "silent", how can you know whether you are truly speaking on behalf of "all".




Saturday, March 28, 2015

Printing to Label Printer

In commerce, shops used to print receipts on a small printer called Receipt Printer. These printers usually do not require a driver. Basically you just treat it as a device and send raw data to it like sending chat messages.

Here I am not talking about what to send to the printer. It is about how to send the raw text to the printer. These printers can generally be connected via Parallel, Serial, USB, WIFI, Bluetooth or Ethernet. The first two is getting rare as most computers and devices now don't have LPT and COM ports.

Modern technology also enable mobile devices like notepads to talk to the printer through wireless communication like Bluetooth or Wifi.

Most shop use a computer/server to manage the Point of Sales system. Therefore, there is always a computing device available. In addition, some may use mobile devices to communicate with the computing device ("server). It is usually the server that does the printing. In some circumstances, the mobile device actually does the printing directly.

In order for the device to talk to the printer, both must be in the same network regardless of whether it is one->one or one->many type of connection. Generally they use a intranet infrastructure if there are two or more devices.

The easiest way is to provide a network system using a standard network router. It need not have a connection to the internet. This method applies to Wifi and Ethernet printer devices.

Another method is to use Bluetooth. This method needs the device to be paired. It does not matter how many can pair with the printer. Some actually does not require pairing. I have little information on this technology.

Once the connection is available, the next task is to use a protocol to talk to the printer.I have not played with Bluetooth enabled printer thus unable to talk about it.

The more common ones usually use Wifi or Ethernet. The two are basically the same except that one is wireless the other one requires a LAN connection.

Since they are connected via network, the best protocol is of course Sockets. To use sockets, devices must be identified by a IP address and a port number. There are plenty of programs that could perform sockets. It will depend on what programming language you use. Just look for "Sockets" in your programming language and you should be able to get plenty of example on how to do it.

No matter what programming language you use, it generally follows the pattern of "opening a connection", "write to the connection" and "close the connection", Here I use PHP as an example.

The very first thing is to connect to the printer. Therefore we use "fsockopen" like ths

$mysock = fsockopen("192.168.0.100", "9100");

The IP address varies according to your network setting. The port number is generally set as 9100. The command allows us to open a connection to the printer.

Once the connection is open, it is treated like any media connection (e.g. file). It is therefore appropriate to use fwrite command (file write) to write to it. Since you generally do not expect a communication to be sent from the printer, you do not need to do fread (file read).

The fwrite command looks like this.

$written = fwrite($mysock, "my text", 7);

It is always good to include the length of the text you are writing. This method of writing to a device is generally referred to as "streaming". When you do streaming with fwrite, there is a peculiar thing that you must always remember. You may write 10000 characters to the printer. Not all the 10000 will be successfully sent. Some will be lost.

Luckily fwrite does returns a number indicating what was successfully sent. You just need to get the returned value and use a substr command to write the rest of the string till all are written. The following code is copied from internet.

function fwrite_stream($fp$string) {
    for (
$written 0$written strlen($string); $written += $fwrite) {
        
$fwrite fwrite($fpsubstr($string$written));
        if (
$fwrite === false) {
            return 
$written;
        }
    }
    return 
$written;
}


I am always amazed as to why fwrite never ensure that all the characters are written. Anyhow, there must be a reason for it.

OK. You now have written the text over to the printer. Obviously you do not want to keep the connection open. The next natural step is to close the connection.

fclose($mysock);

Is it not simple? Actually the hard part is to figure what to sent to the printer. Generally you have to use "ESC" code to achieve this. Most printer actually use Ascii 27 (HEX 1B) to indicate that the text follows is a command instead of pure text. PHP have a nice way of allowing this by another "escape" code. It uses "\x" to indicate that the next two character after it is a HEX code. When PHP sends the text "\x1B" it becomes a single character that is equal to Ascii 27.

I shall not go too deep into this except that most printers expect a start code and a end code. It depends on what code the printer uses. This allow the printer to start interpreting the data and stops all activity accordingly.

If you are thinking of using an iOS device to do it. I suggest you do a deep research first before even trying. Apple does not allow user to even use their own programming codes on iOS devices. Every program that you want to run on iOS has to be code signed (from Apple). This means that you need to pay Apple ($99 a year for personal codes) to write and use your own code in iOS. No wonder people want to "jailbreak" iOS.

Android also requires you to pay but it is a one time payment only. Furthermore, if you do not want to sell your app in Google Play Store, you still can write your own and use it on Android without paying.



Thursday, March 26, 2015

Transparent background PNG with Google Map

I used to have this problem with using PNG icons on Google Map. It just refused to honor the PNG setting for transparency. This applies to GIF too.

Recently, I have accidentally deleted "New PCN on Bike" map so I had to create a new one from the SHP files which I exported. Again I faced with the issue of icon transparency. Some how I downloaded PNGs from the internet and they all have transparency background enabled. Why then my own creation cannot work?

I tried using graphic editors to see what is the difference between my own PNG and internet ones. Since the PNG are actually icons, I start to search for icon editors instead. No point using a graphic editor that could edit large bitmap files for such a small picture.

One of the icon editor is a shareware but its earlier version is free. This app is called IconFX 1.6. When I open my PNG and compare with other PNG, I noticed that my background is solid color whereas other PNG is "checkered". There is actually no color on the "checkered" area. It is then I realize that I don't even have to set transparency for the PNG files. Just delete the unwanted part and I have transparency. It is as simple as that.

With the recent Google change of heart on the Google Map, icon are now available and more than 5 layers are allowed. The map now looks nicer with many layers.



Wednesday, March 18, 2015

Printing on receipt printer using PHP

Printing in PHP is actually not a right solution. In windows PHP, it does have a dll to do printing. On Mac, and others, you don't have such luck. PHP is server side script which could be anywhere in the world. Why do you need to send print commands at the server? Actually it is usually used in business where the client sent a print copy to the company like for example placing an order. However, the use is very limited. Most of the time the company employee will print using local browser to the local printer.

PHP printing does have its use if it is used within a close vicinity of the user like for example a retail shop. It usually employs one printer for all the requests. The printouts are usually receipts printed in narrow stripes of paper. That's why they are also called "receipt printer". This is especially useful in Point of Sale (POS) system. It is easier to write a web based POS program than a custom application.

Now, it defeats the purpose of having a web based program when you need to install print drivers on the user's computer just to do printing. Why not send print commands directly to the printer? Yes. it is actually done in this way.

There exists a series of printers that does not require drivers. They accept text as input. The early printers usually coded the text using ASCII "ESC" to format the printout. Thus it is usual to refer to this kind of printing as ESC POS because both are closely associated with each other.  Epson is the first one that patented the codes.

With the advance of technology, using a tablet or iPad to do mobile POS is becoming a trend. Device like iPad generally do not have print drivers. It is therefore well suited to run POS systems. The printers that works with mobile devices are usually bluetooth,  WIFI or network printers.

The PHP program to do printing is quite simple. In a few lines of code the printing can be done.

The program starts with

$fs = fsockopen(192.168.0.1.111, 9100);

You can see that the address is actually an Local IP address. 9100 is the normal port used.

The printing starts with an escape code ESC @. This is a command to initiate the printer.

$bytes = fwrite($fs, "\x1B@");

The next series of "fwrite" usually contains a series of ESC codes followed by text to format the text according to the coding commands. There are simply too many such coding commands to be described here.

The last "fwrite"  will be the ESC i - a command to cut paper. Some printers use GS V n to do paper cutting.

It is well known that fwrite don't always send all the data when used on "streams". The term normally refer to sending a series of data (streaming) to remote connected devices. As fwrite does return a value representing the number of bytes sent, it is usually used within a loop where a total byte count is kept and the fwrite is continuous send with the remainder text as value using substr($string, total_byte_sent) as value. You can read about "substr" command in PHP documentation.

After sending all the data, the last step is of course to close the stream

fclose($fs);

It is as simple as that. Actually it took me a week just to write this code as it is the first time I tried printing to streams in PHP.

In real life, the text are usually submitted form data or database so you normally have to use $_POST["var"] or SQL to get the text and then add the ESC codes to format it.

Below is a sample code.

function fwrite_stream($fp, $string) {
    for ($written = 0; $written < strlen($string); $written += $fwrite) {
        $fwrite = fwrite($fp, substr($string, $written));
        if ($fwrite === false) {
            return $written;
        }
    }
    return $written;
}
$fp = fsockopen("192.168.1.3",9100);
if (!$fp){
    die("Cannot open sock");
}
$mytext="Hello this is a test print 13 ";
$string="\x1B@".$mytext."\x1Bd\x07\x1Bi";
$bytes=fwrite_stream($fp, $string);
fclose($fp);
printf('wrote %d bytes',$bytes);




Sunday, February 15, 2015

Internet Privacy - what is that?

Networking used to be totally private. In the early days prior to www you probably can only join BBS (Bulletin Board). Unless you talk a lot, nothing was revealed about you.

Come WWW. It still worked the same until people start to find out about you so that they could send you advertisements. Google, Yahoo etc got their finances doing just that.

How do others find out about you. Simple. Every search you do is recorded. It will show your habit, your liking, your interest. A good profiler can construct a personality trait just from your search habits.

You think that is about all? Think again. It is not just your search that is recorded. Internet service provider practically knows every internet activity that you do over the internet. Internet snoopers can also sniff out network packages pertaining to you. That's why privacy proponents insists that internet access be incognito.

Recently the great news about the killing of Osama bin Laden showed that the house he lived in has no internet or mobile connection. He is probably aware of the snooping capability and thus only rely on human courier.

There are talks about terrorist watch list. How in the world would they form the watch list unless they track your activities. For example, once I looked up information of AK47 (Assault Riffle) because I want to know where is the "safety catch". By just looking up this information, I probably end up in the watch list as normal people don't look up information of that kind. I showed that I have interest in fire arms and thus may link to killing or terrorist activity. This is how scary it is.

To us common people, we don't really need to fear such collection of information unless we are doing something covert and don't want others to know about it. The information collected about us are probably used to send us ADS. Obviously, you will be profiled to see if you have criminal traits or even terrorist traits.

Many privacy advocates don't even want to be profiled. They want to have the freedom to surf the internet incognito. Many internet browsers start to provide "incognito" window ( a browser window that will not record your activity). They even have a "do not track" setting. The former make it slightly less easy for people to track you. The latter is almost useless unless companies respect your setting and don't track you. The end result is just some meager efforts to placate users. There is no stopping others from tracking you especially government agencies. Unless you totally refrain from surfing net, you will be tracked.

Internet users knows that they are being tracked so they have counter measures. Virtual Private Network (VPN) is used to surf net under "total" privacy. You access to the VPN server and then surf from there. Since you only access to the server and the connection is encrypted, it makes it very difficult to track what you do at the server. Obviously, your activity is still know by the VPN server but it is still better than nothing.

Some VPN server even provide free access. I am not that paranoid thus I never subscribe to it. Just do a search for VPN and surf to find the number of providers available.

I really don't care about being profiled as I am just a poor nobody. What I hate is the ADS. Well, I use Firefox that have good plugins that blocks most ads. In Chrome, I don't surf with it. It is just used for mails and social networks (my Firefox even blocks Javascript from running). I do have Facebook adBlock installed plus the not-so-effective ABP. It is good enough for me.




Sunday, February 01, 2015

Communicating with Apple Web Services (GSX) via Filemaker

Web services according to WikiPedia is "a method of communication between two electronic devices over a network." There are websites that provide information as a service. Sites like Google Language API which allows you to translate your website directly without you having to create the translation yourself. This means you could translate your web site to hundreds of languages just with the web services code.

In plain language, web services allows you to call a web site from your website by providing a request, or consuming a request ( a most confusing term), with some data. The web site will then provide you with the result. For example, I send a request to Google Language API with "Japanese" as the required language and "How to speak Japanese" as the data. Google Language API will understand your request and responds with the result as "日本語を話す方法". When you change the language to Korean, and use back the same data, the API will respond with "일본어를하는 방법". Isn't that easier than you writing three different pages each with a different language?

Some web sites provide more than just one functionality. You can actually use the service to perform various actions by using it like a "function" with "parameters". In layman language, it means you need to tell the web service what you want to do with the data provided by you. The web services will understand your request and perform the exact action then return you the result. For example, I can go to a plant information web site and do search, update, create, delete, etc. just by calling the same address with different info.

In a web page, we will normally use Javascript to do the calling and showing the response using the technique call AJAX and a newer technique called JSON as data. It has all the functionality available to do it. You just need to compose what to send and get what is returned.

I have the opportunity to write programs using Filemaker (A database program owned by Apple). It has very good interface that allow very easy creation of database interfaces and web pages. However, its scripting facility is a bit lacking. This is especially true when trying to use the technology above to do translation. You practically have to write a code to do the functionality then write the code that make use of the functionality. That is double the work. Luckily there are plug-in that expand the capability of the application.

The following is a description of what I did to call a Web Service from Apple itself using Filemaker. It is a web service provided by Apple to its agents that provide repair services to its customers. The service provides a number of requests with its associated data. For example, if I need to order a spare part, I will call the web services with the request "orderPart" and "xxxxxx" as part number. Apple will then create an entry in its database that records your request and then send the part to you.

The request is send as a XML that contains the "request action" and the data. The response is also a XML that contains the result of the request. In this way user will see the same display yet the transaction is made in the back ground. The Filemaker program will then display the respond data so that user can see the result of the transaction.

Actually it is easier said than done. There is no such functionality available to talk to web services. Filemaker does have a "insert from URL" function that could call a web site and display the result in a field (a place where you can type in a form). However, it only shows the XML returned from Apple directly which is mostly not understood by user. Its XML facility is also not suited for manipulation with XML in this way. Thus the task is to create a code that could call the web services, send the request in XML format and translate the result to user in a readable format.

The very first task is to create the proper XML. Since there is no such function, it has to be created. XML node is generally in the form "<node>value</node>". As you can see, creating it is not a problem. So instead of typing the "node" and the "value" manually, you just need to call the subscript and pass it with the correct parameters.

Problem is that Filemaker (FMP) cannot pass multiple parameters. It does not have arrays too. There is, however, a "List" function that you can use like "list(value1,value2)". Thus you must combine the two information into one by using "list" before passing it as a parameter. You can even create a sort of array by creating a list within a list.

The XML example above is the basic format. XML, like HTML, also can contain properties. It is in the form "<node property='xxxx'>value</node>". Obviously these nodes can be nested. Setting the property nodes aside (as it is normally not used in "body"). There are four ways to create the XML.

1. The beginning node ("<node>"). With this and the ending node, you can create a nested node to what ever level you want.
2. The ending node ("</node>")
3. The complete node with value ("<node>value</node>").
4. The NULL node ("<node/>")

It is very easy to take the first parameter and treat it as a node by enclosing it with "<" and ">". The value is placed next then the first parameter is used again by enclosing it with "<" and ">
".

For those that only need the node name like 1,2, 4 above. It is constructed accordingly.

The value must not contain characters used by XML itself like "<" and ">". Therefore all the values have to be filtered or modified to ensure that the value does not end up as the XML itself. This is called "escaping". With this we are able to construct any XML body. This script will then be store as a script by itself. It always write to a global variable like $$xml so that it does not even need to return a value. The script then becomes a function that create xml nodes.

How then should we add headers. It is very simple. Since we always access to the same address, the header seldom changes. Why not just store it as a plain variable? This is exactly what I did.

In another script we will assemble the xml step by step. Fist we store the header into the variable $$xml. Then we use "run script" to run the script that creates the xml by passing the appropriate values beginning with a code that define what type of nodes we are creating. Repeat the subscript till the whole xml is complete. The result is then a well formed xml. You could even test the output by storing the $$xml in a field or just a custom dialog to ensure that the xml is correctly form by copying and pasting the result in a xml editor.

With the xml available, the next task is to send it to the Apple web services (GSX). Luckily, this functionality is available as a plug-in. BaseElements has the plug-in that could do a post to a website and get a respond into a variable instead of a input field. This functionality is exactly what we need to talk to the server.

The last part is to get the result out of the xml. This functionality is again not available. However, BaseElements does have the functionality to extract values from the xml. It may not be the functionality that I am looking at but at least it can be done. The best way is to transform the whole response xml into something  that is humanly manageable like an array without having to write long codes to do it. But then with the limitations, it is still better than nothing.

The conclusion is that Filemaker can talk to web services. With the database capability, getting chunks data out of the web services is a possibility.

MBS has an excellent example of communicating with GSX. MBS Blog.

Apple will be changing the format used for sending and receiving data.  Please go to part 2 to see how it could be done.