ʹÓÃSAX½âÎöXML
SAX£¨Simple API for XML¼ò³ÆSAX£©Ê¼þÊÇÎÞ״̬µÄ£¬Ò²¾ÍÊÇ˵£¬µ±½ÓÊÕµ½×Ö·ûÊý¾ÝµÄʼþºó£¬²¢²»ÖªµÀ¸Ã×Ö·ûÊý¾ÝÊÇÄÄÒ»¸öÔªËصÄ
ÄÚÈÝ¡£Í¬ÑùµØ£¬µ±ÊÕµ½ÔªËØ¿ªÊ¼µÄʼþºó£¬Ò²ÎÞ·¨ÖªµÀ¸ÃÔªËØÊÇ·ñÓи¸ÔªËØ£¬ÊÇ·ñÓÐ×ÓÔªËØ£¬ÕâÊÇ
SAXºÍDOM²»Í¬µÄµØ·½¡£SAX½âÎöÆ÷±¾Éí²¢²»ÌṩԪËصÄÉÏÏÂÎÄÐÅÏ¢£¬ËùÓÐÏà¹ØÐÅÏ¢µÄ¼Ç¼ÐèÒªÎÒÃÇ×Ô
¼º±à³ÌȥʵÏÖ
SaxXmlÀà¼ÓÔØXMLÊý¾ÝÁ÷£¬£¨Ä¿Ç°ÓÃ×Ö·û´®´úÌ棩£¬½¨Á¢½âÎö¹¤³§£¬Éú²úSAX½âÎö¶ÔÏó
import java.io.ByteArrayInputStream;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
public class SaxXml {
private SaxXml() {
}
SaxXml(String xmlFile) {
try{
String xmltest = "<?xml version=\"1.0\" encoding=\"gb2312\"?>"
+"<home>"
+"<name>ÕÅÈý</name>"
+"<sex>ÄÐ</sex>"
+"<age>20</age>"
+"</home>";
byte[] data1 = xml.getBytes();
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
SAXParser sax = factory.newSAXParser();
sax.parse(new ByteArrayInputStream(data1), XmlHandler.handler/*new XmlHandler()*/ );
} catch (ParserConfigurationException pce) {
System.out.println("Could not create that parser.");
System.out.println(pce.getMessage());
} catch (SAXException saxe) {
System.out.println("Problem wITh the SAX parser.");
System.out.println(saxe.getMessage());
} catch (Exception e) {
e.printStackTrace();
&n
Ïà¹ØÎĵµ£º
/// <summary>
/// DataTable-------------------->XML --String
/// </summary>
public static String ToXmlString(DataTable dt)
{
StringWriter tr = new StringWriter();
try
{
dt.WriteXml(tr); ......
XMLѧϰÍêÁË£¬ÀÏʦ˵ÔÚÃæÊÔµÄʱºòÓпÉÄÜÒªÎʵ½ÕâЩ£¬ËùÒÔÓÖÕÒÁËЩ×ÊÁÏ£¬ÔÚMLDNµÄÕâ¶ÎÈÕ×ÓÀÀÏʦÃǶ¼°Ñ¸÷¸öÃæÊÔÖÐÓпÉÄÜÒªÎʵ½µÄÎÊÌⶼ°ïÎÒÃÇÒ»Ò»×ܽᣬÕæµÄºÜ¸ÐлMLDNµÄÈ«²¿ÀÏʦ,ÏîÄ¿ÀÏʦ°ïÎÒÃÇÈÏÕæµÄ½²½âÏîÄ¿£¬¸¨µ¼ÏîÄ¿£¬½ÌѧÀÏʦ°ïÎÒÃÇÈÏÕæ×ܽá¸÷¸ö¼¼Êõ£¬¸Ðл£¬ÕæµÄÊǸÐл£¬ºÇºÇ£¬ÎÒ»áŬÁ¦¸ãºÃµÄ
JavaÖÐËÄÖÖXML ......
ʹÓÃjavascript´´½¨Microsoft XML DOM,¾Í¿ÉÒÔÍê³ÉÕâÒ»¹¤×÷.
// ×°ÈëÊý¾Ý.
var source = new ActiveXObject("Microsoft.XMLDOM");
source.async = false
source.load("history.xml");
// ×°ÈëÑùʽ±í.
var stylesheet = new ActiveXObject("Microsoft.XMLDOM");
stylesheet.async = false
stylesheet.load( ......
ÏÖÔÚÎÒÃÇÔÝÇÒʹÓÓ¼Çʱ¾”À´´´½¨ÎÒÃǵÄXMLÎļþ°É¡£ÏÈ¿´Ò»¸öXMLÎļþ£º
¡¡¡¡Àý1
¡¡¡¡¡´?xml version="1.0" encoding="gb2312" ?¡µ
¡¡¡¡¡´²Î¿¼×ÊÁÏ¡µ
¡¡¡¡ ¡´Êé¼®¡µ
¡¡¡¡ ¡´Ãû³Æ¡µXMLÈëÞ«½â¡´/Ãû³Æ¡µ
¡¡¡¡ ¡´×÷Õß¡µÕÅÈý¡´/×÷Õß¡ ......
package com.jcauto.action;
import java.util.ArrayList;
import java.util.List;
public class ContentRsp {
private String resultCode;
List<ContentInfo> contentList = new ArrayList<ContentInfo>();
public void addContent(ContentInfo contentInfo) {
contentList.add(contentI ......