[ת]Android¶ÁдXML£¨ÉÏ£©——package˵Ã÷
--±¾ÎÄÕª×Ôhttp://www.moandroid.com/?p=508
By: º£ÊÐò×Â¥ | In: Android¿ª·¢
3 ¾Å 2009
XML ¾³£ÓÃ×÷ Internet ÉϵÄÒ»ÖÖÊý¾Ý¸ñʽ£¬ÆäÎļþ¸ñʽÏë±Ø´ó¼Ò¶¼±È½ÏÇå³þ£¬ÔÚÕâÀïÎÒ½áºÏAndroidƽ̨£¬À´ËµÃ÷Android SDKÌṩµÄ¶ÁдXMLµÄpackage¡£
Ê×ÏȽéÉÜÏÂAndroid SDKÓëJava SDKÔÚ¶ÁдXMLÎļþ·½Ã棬Êý¾Ý°üÖ®¼äµÄ¹Øϵ¡£Android ƽ̨×î´óµÄÒ»¸öÓÅÊÆÔÚÓÚËüÀûÓÃÁË Java ±à³ÌÓïÑÔ¡£Android SDK ²¢Î´Ïò±ê×¼ Java Runtime Environment (JRE) ÌṩһÇпÉÓù¦ÄÜ£¬µ«ËüÖ§³ÖÆäÖкܴóÒ»²¿·Ö¹¦ÄÜ¡£Java ƽ̨֧³Öͨ¹ýÐí¶à²»Í¬µÄ·½Ê½À´Ê¹Óà XML£¬²¢ÇÒ´ó¶àÊýÓë XML Ïà¹ØµÄ Java API ÔÚ Android Éϵõ½ÁËÍêÈ«Ö§³Ö¡£¾ÙÀýÀ´Ëµ£¬Java µÄ Simple API for XML (SAX) ºÍ Document Object Model (DOM) ÔÚ Android É϶¼ÊÇ¿ÉÓõģ¬ÕâЩ API ¶àÄêÒÔÀ´Ò»Ö±¶¼ÊÇ Java ¼¼ÊõµÄÒ»²¿·Ö£¬½ÏÐ嵀 Streaming API for XML (StAX) ÔÚ Android Öв¢²»¿ÉÓᣵ«ÊÇ£¬ Android ÌṩÁËÒ»¸ö¹¦ÄÜÏ൱µÄ¿â¡£×îºó£¬Java XML Binding API ÔÚ Android ÖÐÒ²²»¿ÉÓã¬Õâ¸ö API ÒÑÈ·¶¨¿ÉÒÔÔÚ Android ÖÐʵÏÖ¡£Android SDKÌṩÁËÈçÏÂpackageÀ´Ö§³ÖXMLµÄ¶Áд£º
°ü
¹¦ÄܽéÉÜ
javax.xml
¸ù¾Ý XML ¹æ·¶¶¨ÒåºËÐÄ XML ³£Á¿ºÍ¹¦ÄÜ¡£
javax.xml.parsers
ÌṩDOMºÍSAX·½·¨½âÎöXMLÎĵµ
org.w3c.dom
W3CÌṩµÄʹÓÃDOM·½·¨¶ÁÈ¡XML
org.xml.sax
ÌṩºËÐÄSAX APIs
org.xmlpull.v1
¶îÍâ²¹³ä˵Ã÷Ï£¬ÔÚandroid.utilÊý¾Ý°üÖÐÒ²ÌṩÁËÒ»¸öÀàXml£¬²»¹ýÕâ¸öÀà¾ÍÊÇ°ÑÒÔÉÏpackage¼òµ¥·â×°ÁËÏ¡£
¶ÁÈ¡XMLÖ÷ÒªÓÐ2ÖÖ·½·¨£ºDOMÓëSAX(Simple API for XML)£¬ÔÚÕâÀï¶ÔÕâ2ÖÖ·½·¨·Ö±ð¼ÓÒÔ˵Ã÷¡£
DOM(Îĵµ¶ÔÏóÄ£ÐÍ)£¬ÎªXMLÎĵµµÄ½âÎö¶¨ÒåÁËÒ»×é½Ó¿Ú£¬½âÎöÆ÷¶ÁÈëÕû¸öÎĵµ£¬È»ºó¹¹ÔìÒ»¸öפÁôÄÚ´æµÄÊ÷½á¹¹£¬È»ºó´úÂë¾Í¿ÉÒÔʹÓÃDOM½Ó¿ÚÀ´²Ù×éÕû¸öÊ÷½á¹¹£¬ÆäËûµãÈçÏ£º
Óŵ㣺Õû¸öÎĵµÊ÷¶¼ÔÚÄÚ´æµ±ÖУ¬±ãÓÚ²Ù×÷£»Ö§³Öɾ³ý¡¢Ð޸ġ¢ÖØÐÂÅÅÁеȶ๦ÄÜ¡£
ȱµã£º½«Õû¸öÎĵµµ÷ÈëÄڴ棨¾³£°üº¬´óÁ¿ÎÞÓõĽڵ㣩£¬ÀË·Ñʱ¼äºÍ¿Õ¼ä¡£
ʹÓó¡ºÏ£ºÒ»µ©½âÎöÁËÎĵµ»¹ÐèÒª¶à´Î·ÃÎÊÕâЩÊý¾Ý£¬¶øÇÒ×ÊÔ´±È½Ï³ä×㣨ÈçÄÚ´æ¡¢CPUµÈ£©¡£
ΪÁ˽â¾öDOM½âÎöXMLÒýÆðµÄÕâЩÎÊÌ⣬³öÏÖÁËSAX¡£SAX½âÎöXMLÎĵµÎªÊ¼þÇý¶¯£¬Ïêϸ˵Ã÷ÇëÔĶÁAndroid¶ÁдXML£¨ÖУ©–SAX¡£µ±½âÎöÆ÷·¢ÏÖÔªËØ¿ªÊ¼¡¢ÔªËؽáÊø£¬Îı¾¡¢ÎĵµµÄ¿ªÊ¼»òÕß½áÊøʱ£¬·¢ËÍʼþ£¬ÔÚ³ÌÐòÖбàдÏìÓ¦ÕâЩʼþµÄ´úÂ룬ÆäÌصãÈçÏ£º
Óŵ㣺²»ÓÃÊÂÏȵ÷ÈëÕû¸öÎĵµ£¬Õ¼ÓÃ×ÊÔ´ÉÙ¡£ÓÈÆäÔ
Ïà¹ØÎĵµ£º
(Ò») ÏȽ²Ò»ÏÂXMLÖеÄÎïÊâ×Ö·û£¬ÊÖ¶¯ÌîдʱעÒâһϡ£
×Ö·û ×Ö·ûʵÌå
& &n ......
XmlDocument doc = new XmlDocument();
string strtxt = "";
doc.Load(Server.MapPath("XMLFile1.xml"));
&nbs ......
²»½âÊÍÁË£¬×Ô¼º¿´´úÂë°É.......................
using System;
using System.Text;
using System.Data;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Xml;
namespace Gogofly.CommonOperation
{
/// <summary>
/// ......
---xml²ð·ÖÒÔ²»¶¨¿Õ¸ñΪ·Ö¸î·ûºÅµÄ×Ö·û´®
--²âÊÔÊý¾Ý
if object_id('[tb]') is not null drop table [tb]
create table [tb]([a] varchar(200))
go
insert [tb]
select 'aaaa bbbb cccc dddd'
insert [tb]
select 'eeeeee ffff hhhh   ......
xml_parse½âÎöxmlÎļþʱºò£¬
ºÜÓпÉÄܲ»½ö½öµ÷ÓÃÒ»´Îcharacter_handler¡£
ËùÒÔÔÚ»ñµÃxml½ÚµãµÄÎı¾ÐÅÏ¢µÄʱºò£¬ÒªÓÃÁ¬½ÓÔËËã".="¡£
²Î¿¼ http://jp2.php.net/manual/ro/function.xml-set-character-data-handler.php
ken at positive-edge dot com
30-Jan-2002
01:20
the function handler is called ......