×

Discussion Board

Results 1 to 8 of 8

Thread: KXml Parsing

  1. #1
    Regular Contributor
    Join Date
    Nov 2010
    Location
    Egypt,Mansoura
    Posts
    80

    KXml Parsing

    I want to parse an xml file that contain UTF-8 Encoding character

    how can i use KXml with it
    Let The Impossible Happen!!!

  2. #2
    Regular Contributor
    Join Date
    Nov 2010
    Location
    Egypt,Mansoura
    Posts
    80

    Re: KXml Parsing

    I Tried to inputStream and the problem in the simulator Is in the parser.nextText() WhY?
    Let The Impossible Happen!!!

  3. #3
    Regular Contributor
    Join Date
    Jan 2011
    Posts
    103

    Re: KXml Parsing

    hi,
    i am facing the same problem i am new to j2me.i want to do xml parsing.can you share your code with me for xml parsing.

    Thanks in advance

  4. #4
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: KXml Parsing

    i guess you used setInput(java.io.InputStream is, java.lang.String _enc) and precised "UTF-8" as encoding.
    It seems one correct way of doing it, which would mean that your xml may be incorrect.
    can you post a short xml that causes the problem ?

  5. #5
    Regular Contributor
    Join Date
    Nov 2010
    Location
    Egypt,Mansoura
    Posts
    80

    Re: KXml Parsing

    Quote Originally Posted by njzk2 View Post
    i guess you used setInput(java.io.InputStream is, java.lang.String _enc) and precised "UTF-8" as encoding.
    It seems one correct way of doing it, which would mean that your xml may be incorrect.
    can you post a short xml that causes the problem ?
    Code:
    class GetFeedWorker implements Runnable{
            public void run()  {
    HttpConnection httpConnection = null;
                InputStream in = null;
                String url = "http://news.google.com.eg/news?pz=1&cf=all&ned=ar_eg&hl=ar&topic=e&num=3&output=rss";
                try {
                    httpConnection = (HttpConnection) Connector.open(url);
                    in = (InputStream) httpConnection.openInputStream();
                    KXmlParser parser = new KXmlParser();
                    parser.setInput(in,"utf-8");
                    int eventType = XmlPullParser.START_TAG;
                    while (eventType != XmlPullParser.END_DOCUMENT) {
                        if(eventType == XmlPullParser.START_TAG) {
                            String startTag = parser.getName();
                            if(startTag != null){
                                startTag = startTag.toLowerCase();
                        
                                if(startTag.equals("title")){
                                    resultsForm.append(parser.nextText().trim());
                                }
                                
                            }
                        }
                        eventType = parser.next();
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                } catch(XmlPullParserException ex){
                    ex.printStackTrace();
                }
    finally{
        if(in != null){
                    try {
                        in.close();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
                if(httpConnection!= null){
                    try {
                        httpConnection.close();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
    
    
    
    
            }
    
            }
        }
    }
    This is the Thread Is used.

    Thank u I Used This Code and it works Fine For me

    i want to share it with u and for shwetadseema request
    Last edited by buffon2009; 2011-01-24 at 20:24.
    Let The Impossible Happen!!!

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    20

    Re: KXml Parsing

    Hi. I developed a simple example about using KXML in Java Me:

    http://www.java-n-me.com/2011/07/rea...n-java-me.html

    Hope it hepls someone

  7. #7
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: KXml Parsing

    In J2me, JSR 172 Web services API also provide a SAX parser in XML Parser package which can used in place of KXML as Sax parser takes lesser runtime memory as compared to Dom.

    For Example refer to http://www.developer.nokia.com/Commu...arsing_Example
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    20

    Re: KXml Parsing

    Thanks for sharing this information. Sounds like a great API, but some times devices doesn't provide the JSR172 API and for that reason KXML is good choice for them.

    thanks again.

Similar Threads

  1. Kxml parsing to retrieve attributes
    By yatibawri in forum Mobile Java General
    Replies: 6
    Last Post: 2011-05-10, 05:20
  2. Parsing wbxml file to xml file using kxml parser
    By ramyashashe in forum Mobile Java General
    Replies: 18
    Last Post: 2010-05-17, 15:56
  3. KXML parsing problem on different devices
    By bumble-bee in forum Mobile Java General
    Replies: 2
    Last Post: 2009-11-20, 10:07
  4. Replies: 0
    Last Post: 2009-06-09, 14:49
  5. Http error | Kxml parsing
    By javame in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2003-09-12, 09:35

Posting Permissions

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