¿ìËÙÒµÎñͨµÀ

ÔÚJ2ME¿ª·¢ÖнâÎöXML - ±à³ÌÈëÃÅÍø

×÷Õß ØýÃû¼¼Êõ À´Ô´ NET±à³Ì ä¯ÀÀ ·¢²¼Ê±¼ä 2012-07-04
utStream() ); kXMLElement root = new kXMLElement(); try { root.parseFromReader( doc ); } catch( kXMLParseException pe ){ } catch( IOException ie ){ }

ÏÂÃæÊÇÒ»¸öJ2MEµÄÓ¦ÓóÌÐò¼òµ¥ÑÝʾÁËÈçºÎ½âÎöxml¡£Èç¹ûÓÐʱ¼ä¿ÉÒÔдд¸´ÔӵIJâÊÔ³ÌÐò¡£Äã¿ÉÒÔ´ÓÈçϵØÖ·ÏÂÔØÔ´´úÂ룺XMLTest. ÀïÃæ°üÀ¨ÁËkxmlºÍnanoxmlµÄÔ´´úÂ룬Èç¹ûÏëµÃµ½×îеÄÔ´´úÂëÇë²Î¿¼ËûÃǵĹٷ½ÍøÕ¾£¬ÔÚ±¾Õ¾ÌṩÁËkxmlµÄÔÚÏßAPI

package com.ericgiguere.techtips; import java.io.*; import java.util.*; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; import nanoxml.*; import org.kxml.*; import org.kxml.parser.*; /** * Simple MIDlet that demonstrates how an XML document can be * parsed using kXML or NanoXML. */ public class XMLTest extends MIDlet { // Our XML document -- normally this would be something you // download. private static String xmlDocument = "apple" + "orange" + "pear"; private Display display; private Command exitCommand = new Command( "Exit", Command.EXIT, 1 ); public XMLTest(){ } protected void destroyApp( boolean unconditional ) throws MIDletStateChangeException { exitMIDlet(); } protected void pauseApp(){ } protected void startApp() throws MIDletStateChangeException { if( display == null ){ // first time called... initMIDlet(); } } private void initMIDlet(){ display = Display.getDisplay( this ); String [] items; //items = parseUsingNanoXML( xmlDocument ); items = parseUsingkXML( xmlDocument ); display.setCurrent( new ItemList( items ) ); } public void exitMIDlet(){ notifyDestroyed(); } // Parses a document using NanoXML, looking for // "item" nodes and returning their content as an // array of strings. private String[] parseUsingNanoXML( String xml ){ kXMLElement root = new kXMLElement(); try { root.parseString( xml ); Vector list = root.getChildren(); Vector items = new Vector(); for( int i = 0; i < list.size(); ++i ){ kXMLElement node = (kXMLElement) list.elementAt( i ); String tag = node.getTagName(); if( tag == null ) continue; if( !tag.equals( "item" ) ) continue; items.addElement( node.getContents() ); } String[] tmp = new String[ items.size() ]; items.copyInto( tmp ); return tmp; } catch( kXMLParseException ke ){ return new String[]{ ke.toString() }; } } // Parses a document using kXML, looking for "item" // nodes and returning their content as an // array of strings. private String[] parseUsingkXML( String xml ){ try { ByteArrayInputStream bin = new ByteArrayInputStream( xml.getBytes() ); InputStreamReader in = new InputStreamReader( bin ); XmlParser parser = new XmlParser( in ); Vector items = new Vector(); parsekXMLItems( parser, items ); String[] tmp = new String[ items.size() ]; items.copyInto( tmp ); return tmp; } catch( IOException e ){ return new String[]{ e.toString() }; } } private void parsekXMLItems( XmlParser parser, Vector items ) throws IOException { boolean inItem = false; while( true ){ ParseEvent event = parser.read(); switch( event.getType() ){ case Xml.START_TAG: if( event

ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!

·ÖÏíµ½£º ¸ü¶à

Copyright ©1999-2011 ÏÃÃÅÁèÖڿƼ¼ÓÐÏÞ¹«Ë¾ ÏÃÃÅÓÅͨ»¥Áª¿Æ¼¼¿ª·¢ÓÐÏÞ¹«Ë¾ All rights reserved

µØÖ·(ADD)£ºÏÃÃÅÈí¼þÔ°¶þÆÚÍûº£Â·63ºÅ701E£¨¶«ÄÏÈÚͨÅÔ£© Óʱà(ZIP)£º361008

µç»°£º0592-5908028 ´«Õ棺0592-5908039 ×ÉѯÐÅÏ䣺web@lingzhong.cn ×ÉѯOICQ£º173723134

¡¶ÖлªÈËÃñ¹²ºÍ¹úÔöÖµµçÐÅÒµÎñ¾­ÓªÐí¿ÉÖ¤¡·ÃöB2-20100024  ICP±¸°¸:ÃöICP±¸05037997ºÅ