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.
Ïà¹ØÎĵµ£º
Ò»¡¢Libxml2½éÉÜ£º
Libxml2 ÊÇÒ»¸öxmlµÄcÓïÑÔ°æµÄ½âÎöÆ÷£¬±¾À´ÊÇΪGnomeÏîÄ¿¿ª·¢µÄ¹¤¾ß£¬ÊÇÒ»¸ö»ùÓÚMIT LicenseµÄÃâ·Ñ¿ªÔ´Èí¼þ¡£Ëü³ýÁËÖ§³ÖcÓïÑÔ°æÒÔÍ⣬»¹Ö§³Öc++¡¢PHP¡¢Pascal¡¢Ruby¡¢TclµÈÓïÑԵİ󶨣¬ÄÜÔÚWindows¡¢Linux¡¢Solaris¡¢MacOsXµÈƽ̨ÉÏÔËÐС£¹¦ÄÜ»¹ÊÇÏ൱ǿ´óµÄ£¬ÏàÐÅÂú×ãÒ»°ãÓû§ÐèÇóûÓÐÈκÎÎÊÌâ¡£
¶þ¡ ......
ÕâÊǹØÓÚAsp.Net/XMLÉîÈë±à³ÌµÄ¼¼ÊõÊ飬×÷Õß¾«ÐÄÉè¼ÆÁË66¸öʵÀýÏêϸ½éÉÜÁË.Net FrameworkÒÔ¼°XML¼¼ÊõÔÚ.Net FrameworkµÄ±à³Ì·½·¨ºÍ¼¼ÇÉ¡£È«ÊéÓÉ12Õ¹¹³É£¬ÄÚÈݰüÀ¨.Netƽ̨µÄ½¨Á¢¡¢Asp.NetµÄWeb Forms¡¢¿Ø¼þ¡¢Êý¾Ý·ÃÎÊ¡¢Web Service¡¢Asp.NetµÄÉèÖú͸ú×Ù¡¢Asp.NetµÄ°²È« ......
<!--
/* Font Definitions */
@font-face
{font-family:ËÎÌå;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:PMingLiU;
panos ......