×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79

    How to extract specific data from xml format data in j2me??

    I am new in j2me app development & I am developing Location based j2me app for my final year. For that I am using Text Search Feature of Google Places API to search places. In this, by URL we query a place name of our desire & in response URL return result of place(s) name in xml format(Its did not send .xml file, only send data in xml format). Which is as follows-

    HTML Code:
    <PlaceSearchResponse>
    <status>OK</status>
    <result>
    <name>The Taj Mahal Hotel</name>
    <type>lodging</type>
    <type>establishment</type>
    <formatted_address> Apollo Bunder, Opposite Gateway Of India, P J Ramchandani Marg, Colaba, Mumbai, MH, India </formatted_address>
    <geometry>
    <location>
    <lat>18.9223380</lat>
    <lng>72.8333470</lng>
    </location>
    </geometry>
    <rating>4.6</rating>
    <icon> http://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png </icon>
    <reference> CoQBcgAAAOPaRox3TgxkziRCx3GXjgCgx4--UKVRRqKX_V3yMcqxgHfmT_PXwryIh3wjFXvh4cq6Tw9FjFKiNr4pypyIhslOqodRAsAacSO0xhk1LvVqd_WGeda7vaUmImB8sVcxgBpDOvHe1wZXvAiGITBzTa2f6RU4cyi5AKb-Wev4_WHdEhAw2X4zrDX8QUK8niwWrjCDGhSnjoZcIOexbrcWMWP9_fp9p3VIyw </reference>
    <id>aa5ee0d398a7f5c3787a638deaa2e87ffb38436a</id>
    <photo>
    <photo_reference> CnRvAAAAMaSdYSqi7SCjk-CKBOld9QI86Ev_Hqt387TNCynY4iFRutgP8Uw9W-uAlKrIsfrRiQpq3GPwe4Cglk1vNQmnX7-NTgvf_wsW4wPGtGg6rckXrwf9dQ3CyKiZxWkSHaNm9e4jTS6b-5N_RQqGc57xjRIQrnLMro1PpymPTno-9nE7RxoU9EbIYca-2kLc2oSAIVZxw4MtirI </photo_reference>
    <width>960</width>
    <height>1280</height>
    <html_attribution>From a Google User</html_attribution>
    </photo>
    </result>
    </PlaceSearchResponse>
    From this, I want to retrieve data from <status> tag, <name> tag, <formatted_address> tag, <lat> and <lng> tag. How should I done this.... I am stucked here...plz help as soon as possible.

  2. #2
    Registered User
    Join Date
    Sep 2012
    Posts
    31

    Re: How to extract specific data from xml format data in j2me??

    Quote Originally Posted by Rahul More View Post
    I am new in j2me app development & I am developing Location based j2me app for my final year. For that I am using Text Search Feature of Google Places API to search places. In this, by URL we query a place name of our desire & in response URL return result of place(s) name in xml format(Its did not send .xml file, only send data in xml format). Which is as follows-

    HTML Code:
    <PlaceSearchResponse>
    <status>OK</status>
    <result>
    <name>The Taj Mahal Hotel</name>
    <type>lodging</type>
    <type>establishment</type>
    <formatted_address> Apollo Bunder, Opposite Gateway Of India, P J Ramchandani Marg, Colaba, Mumbai, MH, India </formatted_address>
    <geometry>
    <location>
    <lat>18.9223380</lat>
    <lng>72.8333470</lng>
    </location>
    </geometry>
    <rating>4.6</rating>
    <icon> http://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png </icon>
    <reference> CoQBcgAAAOPaRox3TgxkziRCx3GXjgCgx4--UKVRRqKX_V3yMcqxgHfmT_PXwryIh3wjFXvh4cq6Tw9FjFKiNr4pypyIhslOqodRAsAacSO0xhk1LvVqd_WGeda7vaUmImB8sVcxgBpDOvHe1wZXvAiGITBzTa2f6RU4cyi5AKb-Wev4_WHdEhAw2X4zrDX8QUK8niwWrjCDGhSnjoZcIOexbrcWMWP9_fp9p3VIyw </reference>
    <id>aa5ee0d398a7f5c3787a638deaa2e87ffb38436a</id>
    <photo>
    <photo_reference> CnRvAAAAMaSdYSqi7SCjk-CKBOld9QI86Ev_Hqt387TNCynY4iFRutgP8Uw9W-uAlKrIsfrRiQpq3GPwe4Cglk1vNQmnX7-NTgvf_wsW4wPGtGg6rckXrwf9dQ3CyKiZxWkSHaNm9e4jTS6b-5N_RQqGc57xjRIQrnLMro1PpymPTno-9nE7RxoU9EbIYca-2kLc2oSAIVZxw4MtirI </photo_reference>
    <width>960</width>
    <height>1280</height>
    <html_attribution>From a Google User</html_attribution>
    </photo>
    </result>
    </PlaceSearchResponse>
    From this, I want to retrieve data from <status> tag, <name> tag, <formatted_address> tag, <lat> and <lng> tag. How should I done this.... I am stucked here...plz help as soon as possible.
    Check out the link
    http://www.developer.nokia.com/Commu...2ME-SAX-Parser
    hope this helps you in resolving your issue
    Regards,
    Venkatesh

  3. #3
    Registered User
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79

    Re: How to extract specific data from xml format data in j2me??

    Thanx Vankatesh for your suggestion. But Now I am facing new problem. I am facing an error(java.lang.IllegalArgumentException) at parser.parse(is,srh); and I think this is because of parse() input format. parse() method only accept input in Inputstream or Inputsource format. So how I convert result in method's input format. To pasre result, parse() method only accept input in Inputstream or Inputsource format. So how I convert result in method's input format. The code I developed To take result & for xml parsing is pasted below-

    ContentConnection con = null;
    DataInputStream instrm = null;
    ByteArrayOutputStream bytarroutstrm = null;
    byte [] searchdata = null;
    String result = null;

    String url = "https://maps.googleapis.com/maps/api/place/textsearch/xml?query="+stringEncode(SearchTxt.getString())+"&sensor=true&key= *API KEY*";

    try
    {
    con = (ContentConnection) Connector.open(url);
    instrm = con.openDataInputStream();
    bytarroutstrm = new ByteArrayOutputStream();
    int c;
    while((c = instrm.read()) != -1)
    {
    bytarroutstrm.write(c);
    }
    searchdata = bytarroutstrm.toByteArray();
    result = new String(searchdata, 0, searchdata.length);
    XmlParsing xp = new XmlParsing(result);
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    }

    class XmlParsing implements Runnable
    {
    String result;
    InputStream is;
    public XmlParsing(String result)
    {
    this.result = result;
    threadRun();
    }

    public void threadRun()
    {
    (new Thread(this)).start();
    }

    public void run()
    {
    try
    {
    SearchResponseHandler srh = new SearchResponseHandler();
    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
    is = getClass().getResourceAsStream(result);
    try
    {
    parser.parse(is, srh);
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    }
    finally
    {
    try
    {
    is.close();
    }
    catch(IOException e)
    {
    e.printStackTrace();
    }
    }
    Plzzz help me I stuck here because of this problem.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,684

    Re: How to extract specific data from xml format data in j2me??

    If you check the documentation, http://docs.oracle.com/javame/config...efaultHandler) that exception comes when you provide a null stream.
    And after checking how that stream comes, getResourceAsStream is a slightly different thing, it is about reading resource files packed with your application.
    You already use ByteArrayOutputStream for storing the bytes you receive. ByteArrayInputStream would be quite ok to pass them forward to the XML parser.
    In fact you do not really need the bytes, I guess you just wanted to check if you get correct XML from the server. However if you checked it once, and you assume it is going to be fine in the future, you can directly pass the DataInputStream to the parser.

Similar Threads

  1. Displaying data in Table format in J2ME S40
    By s.abulkalamazad in forum Mobile Java General
    Replies: 3
    Last Post: 2011-10-07, 06:06
  2. Replies: 5
    Last Post: 2010-10-14, 12:07
  3. How to write data in CSV format through J2ME coding
    By aparna_bhure in forum Mobile Java General
    Replies: 2
    Last Post: 2009-09-24, 08:21
  4. How to send data in xml format through j2me application
    By galaxy_j2me in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2009-07-16, 13:25
  5. accessing specific data(information page -Engineering Option Data-)
    By mahd_98 in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×