×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    22

    Category and kxml2?!

    Hi everyone

    Does anyone knows how can we categorize things that we recieve from kxml.Let me to bring an example.


    HTML Code:
    <category>
    
    	<item index="1">
                   <title>ME</title>
                   <name>one</name>
    		<name>one</name>
    	</item>
    	
    	<item index="2">
                   <title>Java</title>
                   <name>one</name>
    		<name>two</name>
    		<name>three</name>
    		<name>four</name>
    		<name>five</name>
    	</item>
    	
    </category>
    The goal is to seperate each item with own elements and when i click to "title" elements to take particular informations !!!!!??
    Last edited by xmenus; 2010-07-20 at 14:52.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105

    Re: Category and kxml2?!

    If you do not like to create Java objects for that XML content, you could use the DOM part of kXML like you do in normal XML parsing. Do you know the difference between Pull, SAX and DOM parsers?

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    22

    Re: Category and kxml2?!

    I've red something about them in Java and XML your visual blueprint book but actually i dont have a good definition about these kind of parsers.Let me to say that i've solved this problem as follows but give me any suggestion about this(your opinion).Remeber im doing a book for mobile so it will have a large amount of data.!So this is readXML() method:
    I've declared a Vector[] chapterData that will holds data of each chapter.Let's say chapter one will have twenty pages with text so chapterData[0] takes all these pages and so on and so one,every chapterData[i] will hold text of each chapter than later i will display on Screen[], screens[i] takes chapterData[i]. So what do you thing am im doing anything that will be heavy for RAM of mobiles or even is there any easy method to do something like this(to get same result).?!




    HTML Code:
    int counter = 1;
    	boolean incremented = false;
    	public void readXML(KXmlParser parser) throws XmlPullParserException, IOException
    	{
    		parser.require(XmlPullParser.START_TAG, null, "title");
    		
    		XmlNode node = new XmlNode(XmlNode.ELEMENT_NODE);
    		BookInformations bi = new BookInformations();
    		
    		
    		while(parser.nextTag() != XmlPullParser.END_TAG)
    		{
    			
    			for(int i = 0; i < parser.getAttributeCount(); i++)
    			{
    				node.setAttribute(parser.getAttributeName(i),parser.getAttributeValue(i));
    				
    				String attributeName = parser.getAttributeName(i);
    				String attributeText = parser.getAttributeValue(i);
    				
    				if(attributeName.equals("index"))
    				{
    					bi.setIndex(attributeText);					
    				}
    				else if(attributeName.equals("text"))
    				{
    					bi.setAttributeText(bi.getIndex()+"."+attributeText+"\n");					
    					
    				}
    				if(counter == Integer.parseInt(bi.getId()))
    				{
    					if(incremented == true)
    					{
    						//System.out.println("Incremented");
    						incremented = false;
    					}
    					else
    					{
    						if(chapterData[counter-1].contains(bi.getAttributeText()))
    						{
    							//System.out.println("True");
    						}
    						else if(bi.getAttributeText() ==  null)
    						{
    						}
    						else
    						{
    							chapterData[counter-1].addElement(bi.getAttributeText());
    						}
    					}
    					
    				}
    			}
    			
    			parser.require(XmlPullParser.START_TAG, null, null);
    			String name = parser.getName();
    			String text = parser.nextText();
    			
    			if(name.equals("id"))
    			{
    				bi.setId(text);
    			}
    			else if(name.equals("name"))
    			{
    				bi.setName(bi.getId()+"."+text);
    			}
    		
    			parser.require(XmlPullParser.END_TAG, null, name);
    		}
    		
    		chapterNames.addElement(bi.getName());
    		chapterID.addElement(bi.getId());
    		
    		parser.require(XmlPullParser.END_TAG, null, "title");
    		counter++;
    		incremented = true;
    		
    	}

Similar Threads

  1. game category
    By doomer999 in forum Mobile Java General
    Replies: 6
    Last Post: 2011-03-15, 21:29
  2. Using Nokia-MIDlet-Category
    By bripebar in forum Mobile Java General
    Replies: 2
    Last Post: 2010-01-25, 11:01
  3. Category information and Synchronization
    By gdartigu in forum Tools and SDK Feedback (Closed)
    Replies: 0
    Last Post: 2007-05-14, 10:54
  4. Nokia-MIDlet-Category
    By TwelveParsecs in forum Mobile Java General
    Replies: 2
    Last Post: 2003-09-20, 01:25

Posting Permissions

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