Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Parsing XML from the Net Using the SAXParser


Parsing XML from the Net - Using the SAXParser
http://www.anddev.org/parsing_xml_from_the_net_-_using_the_saxparser-t353.html
What you learn:
You will learn how to properly parse XML
(here: from the net
) using a SAXParser
.
What it will look like:
Description:
0.)
In this tutorial we are going to parse the following XML-File located at the following url: http://www.anddev.org/images/tut/basic/parsingxml/example.xml
:
XML:
<?xml
version
="1.0"
?>
<outertag>
     <innertag
sampleattribute
="innertagAttribute"
>
          <mytag>
               anddev.org rulez =)
          </mytag>
          <tagwithnumber
thenumber
="1337"
/>
     </innertag>
</outertag>
To accomplish the parsing, we are going to use a SAX-Parser
(Wiki-Info
). SAX
stands for "S
imple A
PI for X
ML
", so it is perfect for us
1.)
Lets take a look at the onCreate(...)
-method. It will open an URL
, create a SAXParser
, add a ContentHandler
to it, parse the URL
and display the Results
in a TextView
.
Java:
     /** Called when the activity is first created. */
     @Override
     public
void
onCreate(
Bundle icicle)
{
          super
.onCreate
(
icicle)
;
          /* Create a new TextView to display the parsingresult later. */
          TextView tv = new
TextView(
this
)
;
          try
{
               /* Create a URL we want to load some xml-data from. */
               URL
url = new
URL
(
"http://www.


Ïà¹ØÎĵµ£º

xml»ù´¡

Ò»XML ½âÎöÆ÷
´ó¶àÊýä¯ÀÀÆ÷¶¼ÓжÁÈ¡ºÍ²Ù×÷ XML µÄÄÚ½¨ XML ½âÎöÆ÷¡£
½âÎöÆ÷°Ñ XML ת»»Îª JavaScript ¿É·ÃÎʵĶÔÏó¡£
½âÎö XML
ËùÓÐÏÖ´úä¯ÀÀÆ÷¶¼ÓжÁÈ¡ºÍ²Ù×÷ XML µÄÄÚ½¨ XML ½âÎöÆ÷¡£
½âÎöÆ÷°Ñ XML ÔØÈëÄڴ棬Ȼºó°ÑËüת»»Îª¿Éͨ¹ý JavaScript ·ÃÎ浀 XML DOM ¶ÔÏó¡£
Äú½«ÔÚ±¾½Ì³ÌµÄÏÂÒ»½ÚÖÐѧϰ¸ü¶àÓÐ¹Ø XML DOM µÄ ......

libxml¿â½âÎöXMLÎļþ

Ð÷ÂÛ
LibxmlÊÇÒ»¸öÓÐÃâ·ÑÐí¿ÉµÄÓÃÓÚ´¦ÀíXML¡¢¿ÉÒÔÇáËÉ¿çÔ½¶à¸öƽ̨µÄCÓïÑÔ¿â¡£LibxmlʵÏÖÁ˶Á¡¢´´½¨¼°²Ù×ÝXMLÊý¾Ý¹¦ÄÜ¡£
Õâ¸öÖ¸ÄÏ»ùÓÚÒ»¸ö¼òµ¥µÄXMLÓ¦Óá£
Êý¾ÝÀàÐÍ
Libxml ¶¨ÒåÁËÐí¶àÊý¾ÝÀàÐÍ£¬ËüÒþ²ØÁËÔÓÂÒµÄÀ´Ô´ÒÔÖÂÄã²»±Ø´¦ÀíËü³ý·ÇÄãÓÐÌض¨µÄÐèÒª¡£xmlChar Ìæ´úchar,ʹÓÃUTF-8±àÂëµÄÒ»×Ö½Ú×Ö·û´®¡£Èç¹ûÄãµÄÊ ......

Android£¨Èý£©Êý¾Ý´æ´¢Ö®XML½âÎö¼¼Êõ

½ñÈÕ¼ÌÐøѧϰAndroidÖÐʹÓÃPullµÄXML½âÎö¼¼ÊõʵÏÖ¶ÔXMLÎļþµÄ½âÎöºÍ´´½¨¡£ÓÉÓÚÃ÷ÌìÐÝÏ¢£¬Ê±¼ä±È½Ï³äÔ££¬ËùÒÔÎÒÒ²½«×òÌìδ×ܽáµÄSAX½âÎö¼¼ÊõÔÚ´Ë×ö¸ö×ܽᡣ
Ò»¡¢SAX½âÎö¼¼Êõ
SaxʹÓõÄÊÇʼþÇý¶¯µÄÁ÷ʽ½âÎö¼¼Êõ¡£Ê¼þÇý¶¯µÄÁ÷ʽ½âÎö·½Ê½ÊÇ£¬´ÓÎļþµÄ¿ªÊ¼Ë³Ðò½âÎöµ½ÎĵµµÄ½áÊø£¬²»¿ÉÔÝÍ£»òµ¹ÍË¡£µ±½âÎöµ½ÎĵµµÄ¿ªÊ¼»ò½áÊø¡ ......

GridView ²Ù×÷XMLÎļþ

<?xml version="1.0" standalone="yes"?>
<imgs>
<pic name="/adv_pic/1.jpg" url="http://www.baidu.com/" title="test" />
<pic name="/adv_pic/2.jpg" url="http://www.baidu.com/" title="test" />
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ