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

SAX½âÎöXML(Ô´´úÂ룩

package book.xml;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class SaxXML {
 public static List readXML(String fileName)throws Exception{
  SAXParserFactory spf=SAXParserFactory.newInstance();//´´½¨SAX½âÎöÆ÷¹¤³§¶ÔÏó
  SAXParser saxParser=spf.newSAXParser();//ʹÓýâÎöÆ÷¹¤³§´´½¨½âÎöÆ÷ʵÀý
 
  //´´½¨SAX½âÎöÆ÷ҪʹÓõÄʼþ¼àÌýÆ÷¶ÔÏó
  StudentSAXHandler handler=new StudentSAXHandler();
  saxParser.parse(new File(fileName),handler);//¿ªÊ¼½âÎöÎļþ
  return handler.getResult();//»ñÈ¡½á¹û
 }
 public static void main(String[] args) {
  String filename="student.xml";
  List studentBeans=null;
  try{
   studentBeans=SaxXML.readXML(filename);
  }catch(Exception e){
   System.err.println(e.getMessage());
  }
  if(studentBeans!=null){
   System.out.println("½âÎöstudent.xmlÎĵµµÃµ½µÄѧÉúÐÅÏ¢£º");
   for(int i=0;i<studentBeans.size();i++){
    System.out.println(studentBeans.get(i).toString());
   }
  }
 }
 /**
  * SAXµÄʼþ¼àÌýÆ÷£¬µ±´¦ÀíÌض¨µÄXMLÎļþµÄʱºò£¬¾ÍÐèҪΪ
  * Æä´´½¨Ò»¸ö¼Ì³ÐDefaultHandlerµÄÀàÀ´´¦ÀíÌض¨µÄʼþ
  * ¿ÉÒÔ˵£¬Õâʵ¼ÊÉϾÍÊÇSAX´¦ÀíXMLÎļþµÄºËÐÄ
  * @author wuhailin
  *
  */
 static class StudentSAXHandler extends DefaultHandler{
  //±£´æÒѾ­¶Áµ½¹ýµ«»¹Ã»ÓйرյıêÇ©
  Stack tagsStack=new Stack();
  List studentBeans=new ArrayList();
  StudentBean bean=null;
  /**µ±Óöµ½ÎĵµµÄ¿ªÍ·µÄʱºò£¬µ÷ÓÃÕâ¸ö·½·¨£¬¿ÉÒÔÔÚÆäÖÐ×öһЩԤ´¦ÀíµÄ¹¤×÷*/
  public void startDocument()throws SAXException{
   System.out.println("--------Parse begin---------");
  }


Ïà¹ØÎĵµ£º

as3²Ù×÷xmlÖ®¶þ

·¶ÀýÈçÏ£º
var xml:XML=
         <body>
             text1
             <bar>barText1</bar>
    & ......

C#СTip£ºXml²Ù×÷¼òÃ÷ÊÖ²á 1


1£©XmlÎĵµÊ¾Àý£¨xmlsample.xml£©£º
 
Code
<?xml version="1.0" encoding="iso-8859-1" ?>
<music>
  <song title="Oh,girl">
    <artist>The Chi-lites</artist>
    <genre>Soul</genre>
  &nb ......

C#ÐòÁл¯Óë·´ÐòÁл¯Xml£¬ÀûÓ÷¶ÐÍ×öͨÓû¯´¦Àí

public class yzzSerialize
{
private yzzSerialize()
{ }
private static yzzCache cache = new yzzCache();
public static T GetfromXml<T>(string xmlpath, T t)
{
using (FileStream fs = new FileStream(xmlpath, FileMode.Open, FileAcces ......

½«Êý×éת»¯ÎªXMLÊý¾Ý

/* Author: ÑîÓî  yangyu@sina.cn */
/*
Ó÷¨Ê¾Àý£º
$cls_xml = new cls_xml();
if ($array){
 $cls_xml->array2xml($array);
 echo $cls_xml->getXml(); 
}else{
 echo '';
}
*/
class cls_xml{
        var $xml;
  &nbs ......

´ÓÒ»¸ö·¶Àý¿´XMLµÄÓ¦ÓÃ

ÒýÑÔ
Èç¹ûÄãÒѾ­¿´ÁËAsp.Net AjaxµÄÁ½ÖÖ»ù±¾¿ª·¢Ä£Ê½ ÕâƪÎÄÕ£¬Äã¿ÉÄܺܿì»á·¢ÏÖÕâÑùÒ»¸öÎÊÌ⣺ÔÚÄÇƪÎÄÕµķ½Ê½2ÖУ¬¿Í»§¶Ë½ö½öÊÇ·¢ËÍÁËÒ³ÃæÉÏÒ»¸öÎı¾¿òµÄÄÚÈݵ½·þÎñ¶Ë£¬¶ø·þÎñ¶ËµÄWeb·þÎñ·½·¨Ò²Ö»½ÓÊÕÒ»¸öÀ´×Ô¿Í»§¶ËµÄ×Ö·û´®ÀàÐ͵ÄÊýÖµ¡£¶øºÜ¶àʱºò£¬·þÎñ¶ËµÄ·½·¨ÆÚÍû½ÓÊÕµÄÊÇÒ»¸ö×Ô¶¨ÒåÀàÐÍ£¬»òÕßÊǶà¸ö²»Í¬ÀàÐ͵IJÎÊ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ