Problem to read xml data

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

Post Reply
vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

Problem to read xml data

Post by vedus » Fri Sep 05, 2014 12:53 pm

I am try to read xml data coming from google maps servers,so i use the below code.
The problem is that in the desktop is working but NO in the ios simulator.
i have check in app settings to use the revXML.
i get the error "xmlerr, can't parse xml"
here is the code but i don't know where i do wrong

Code: Select all

[code]Global pUrl
global myarray
Global browserID
Global theUrl
global tTitles
global thehtmlFile
global theData
global Store_lng
Global Lat_lng


on preopencard
  
   if the environment is not "mobile" then exit preopencard



# put the url into var and change the data test1,test2 with coordinates
  put "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=test1&destinations=|test2&mode=walking&language=el&key=" into testmap

# replace the data test1,test2
  put replaceText(testmap, "test2[test2]*",""&store_lng) into testmap
  put replaceText(testmap, "test1[test1]*",""&lat_lng) into testmap

#load the url
  put Url testmap into pUrl
  
  loadPreferences
  
end preOpenCard

 
  --The XML Tree
command loadPreferences

    local tTree
    put readPreferencesToXMLTree() into tTree

    if tTree is empty then
        exit loadPreferences
    end if
    
 
    processPreferencesTree tTree
    answer tTree
    revDeleteXMLTree tTree
end loadPreferences

# This function reads the XML file, and turns it into an XML Tree. The tree is then returned

private function readPreferencesToXMLTree

      local tPreferencesData, tResult
  put pUrl into tPreferencesData

      put the result into tResult
   if tResult is not empty then
            answer error "Failed to read preferences file at location: " & tPreferencesFile
            return empty
      end if
      
      local tTree
      put revCreateXMLTree(tPreferencesData, false, true, false) into tTree
      if tTree is not an integer then
            answer error "Failed to process preferences file with error: " & tTree
            return empty
      end if
      
      return tTree
end readPreferencesToXMLTree

private command processPreferencesTree pTree

      put revXMLNodeContents(pTree, "/DistanceMatrixResponse/origin_address") into torigin
  put revXMLNodeContents(pTree, "/DistanceMatrixResponse/destination_address") into tDest
  put revXMLNodeContents(pTree, "/DistanceMatrixResponse/row/element/duration/text") into tTime
  put revXMLNodeContents(pTree, "/DistanceMatrixResponse/row/element/distance/text") into tMeters

  set the unicodetext of fld "orig" to uniencode(torigin,"utf8")
  set the unicodetext of fld "dest" to uniencode(tDest,"utf8")
   set the unicodetext of fld "meters" to uniencode(tmeters,"utf8")
set the unicodetext of fld "time" to uniencode(ttime,"utf8")
end processPreferencesTree
Last edited by vedus on Tue Sep 09, 2014 4:12 pm, edited 3 times in total.

vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

Re: Problem to read xml data

Post by vedus » Mon Sep 08, 2014 9:28 am

no one have similar problem with xml?

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

Re: Problem to read xml data

Post by Mark » Mon Sep 08, 2014 11:01 am

Hi,

Perhaps you get no replies because your code is really wrong. Try to simplify your code to include almost only the part that doesn't work and post it again. That'll allow me have a quick look at your code and let you know what I think is wrong. Surely, someone with too much time on his hands might try to figure out all of your code, but personally I don't have too much time :-)

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

vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

Re: Problem to read xml data

Post by vedus » Tue Sep 09, 2014 4:12 pm

Thank you Mark.
I have clean my code ..

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

Re: Problem to read xml data

Post by Mark » Tue Sep 09, 2014 5:39 pm

Hi,

You have several XML-related command and functions. Which line exactly causes the error "xmlerr, can't parse xml"?

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

vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

Re: Problem to read xml data

Post by vedus » Wed Sep 10, 2014 7:49 am

Ok i have write again my code and i have try to catch the error.
The error is coming from bad url this answer i get from the simulators (android-iphone)
i have try the "GET" and the "PUT" the same answer.
In the desktop the url is working fine without problems.
here is the code to load the url

Code: Select all

global xmlinfo
on mouseUp

  //put url "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=38.078459,23.734718&destinations=|38.078833,23.736843&mode=walking&language=en&key=" into xmlinfo

  get url "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=38.078459,23.734718&destinations=|38.078833,23.736843&mode=walking&language=en&key="

put the result into pResult
    if tResult is not empty then
      answer "Your operation failed with this error: " &pResult
  end if
  set the unicodetext of fld "xmlfld" to uniencode(xmlinfo,"utf8")

end mouseUp
i have include the stack file as attach if anyone want to test it more easy.
the procedure in the stack is

1: open the stack
2: put the alt and long
3: load the url
4: get the xml
Attachments
googlemaps_matrixdestination.livecode.zip
(4.18 KiB) Downloaded 261 times

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

Re: Problem to read xml data

Post by Simon » Wed Sep 10, 2014 7:05 pm

Hi vedus,
2 problems

Code: Select all

put the result into pResult
    if tResult is not empty then
"t" or "p"?

and to get the thing to work on mobile remove the | pipe in your url.

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

Post Reply