Discussion Board

Results 1 to 2 of 2

Thread: XML Problem

  1. #1
    Registered User MGvision's Avatar
    Join Date
    Jun 2007
    Posts
    10
    hi there!

    I'm using kXML as Lib for parsing XML.
    Code:
    KXmlParser parser = new KXmlParser();	
    				InputStream is = getClass().getResourceAsStream("/vok.vok2");
    				parser.setInput(new InputStreamReader(is));	
    				parser.nextTag();					
    				parser.require(XmlPullParser.START_TAG, null, "teachmaster");
    
    				
    				while (parser.nextTag () != XmlPullParser.END_TAG)
    				{
    					if(parser.getName().equals("header"))
    					{
    						System.out.println("headercheck");
    						parser.require(XmlPullParser.START_TAG, null, null);
    						while (parser.nextTag() != XmlPullParser.END_TAG) 
    						{
    							parser.require(XmlPullParser.START_TAG, null, null);
    							String name = parser.getName();
    							parser.require(XmlPullParser.END_TAG, null, name);
    						}
    						parser.require(XmlPullParser.END_TAG, null, null);
    					}
    					
    			    }
    		
    				parser.require(XmlPullParser.END_TAG, null, "teachmaster");
    				parser.next();
    		
    				parser.require(XmlPullParser.END_DOCUMENT, null, null);
    the XML looks like this:

    HTML Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <teachmaster>
        <header>
          <titel>Unit1</titel>
          <autor>Jens</autor>
          <bemerkungen>ein test</bemerkungen>
          <spreins>German</spreins>
          <sprzwei>Englisch</sprzwei>
          <font></font>
          <fontsize></fontsize>
          <fontlek></fontlek>
          <fontspreins></fontspreins>
          <fontsprzwei></fontsprzwei>
          <fontsyn></fontsyn>
          <fontbem></fontbem>
       </header>
    </teachmaster>
    the error is:

    Code:
    headercheck
    org.xmlpull.v1.XmlPullParserException: expected: END_TAG {null}titel (position:START_TAG <titel>@4:14 in java.io.InputStreamReader@1cb37664) 
    	at org.kxml2.io.KXmlParser.exception(+47)
    	at org.kxml2.io.KXmlParser.require(+83)
    	at mobilelearn$ReadXML.run(+95)

    i would be cool if someone has a hint fo me

    thanks,
    Martin

  2. #2
    Regular Contributor axs's Avatar
    Join Date
    Aug 2006
    Posts
    307
    I guess the problem is that you've setted up parser for any starting tag parser.require(XmlPullParser.START_TAG, null, null); just after you've meet the "header" tag.

    It would be much easier and simpler if you would use the states indicating that you're inside the "header" block, and then simply check for values:

    Code:
    boolean insideHeader = false;
    
    String currentName = "";
    
    while (parser.nextTag () != XmlPullParser.END_TAG) {
    
    
        currentName = parser.getName();
    
    
        if (currentName.equals("header")) {
    
            insideHeader = true;
    
        }
        else if (insideHeader) {
    
            if (currentName.equals("titel")) {
    
                // get data etc...
    
            }
    
        }
    
    }
    Last edited by axs; 2007-06-15 at 07:28.

Similar Threads

  1. 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
  2. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  3. XML parsing problem in Nokia 12
    By codekiller in forum Nokia M2M
    Replies: 2
    Last Post: 2005-04-26, 09:01
  4. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36
  5. 7210 Silent Problem
    By MarkMckim in forum Mobile Java General
    Replies: 1
    Last Post: 2003-03-18, 12:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved