<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    無為

    無為則可為,無為則至深!

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      190 Posts :: 291 Stories :: 258 Comments :: 0 Trackbacks

    編譯環境是jdk1.5+xerces-j-2.8
    源碼為:import java.io.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.XMLReaderFactory;
    import org.apache.xerces.parsers.*;
    ?public class ParseXMLDTD
    {
    ?? ?public void ShowParseResult(String uri)
    ?? ?{
    ?? ??? ?System.out.println("Parse"+"uri"+"File!");
    ?? ??? ?System.out.println("===============================");
    ?? ??? ?ContentHandler Chandler=new ChandlerClass1();
    ?? ??? ?ErrorHandler EHandler=new EHandlerClass1();
    ?? ??? ?DTDHandler DHandler=new DTDHandlerClass1();
    ?? ??? ?try
    ?? ??? ?{
    ?? ??? ??? ?XMLReader MyParser=XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    ?? ??? ??? ?MyParser.setContentHandler(Chandler);
    ?? ??? ??? ?MyParser.setErrorHandler(EHandler);
    ?? ??? ??? ?MyParser.setDTDHandler(DHandler);
    ?? ??? ??? ?MyParser.setFeature("http://xml.org/sax/features/validation",true);
    ?? ??? ??? ?MyParser.parse(uri);
    ?? ??? ?}
    ?? ??? ?catch(IOException e)
    ?? ??? ?{
    ?? ??? ??? ?System.out.println("Error IOException !!!");
    ?? ??? ?}
    ?? ??? ?catch(SAXException e)
    ?? ??? ?{
    ?? ??? ??? ?System.out.println("Error SAXException !!!");
    ?? ??? ?}
    ?? ??? ?
    ?? ?}
    ?? ?public static void main(String args[])
    ?? ?{
    ?? ??? ?String uri=args[0];
    ?? ??? ?ParseXMLErrorLog ParseXMLErrorLogInstance=new ParseXMLErrorLog();
    ?? ??? ?ParseXMLErrorLogInstance.ShowParseResult(uri);
    ?? ?}
    }
    class ChandlerClass1 implements ContentHandler
    {
    ?? ?private Locator locator;
    ?? ?public void setDocumentLocator(Locator locator)
    ?? ?{
    ?? ??? ?System.out.println("The Parser called setDocumentLocator()!!!");
    ?? ??? ?this.locator=locator;
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void startDocument() throws SAXException
    ?? ?{
    ?? ??? ?System.out.println("The Parser called startDocument()!!!");
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void endDocument() throws SAXException
    ?? ?{
    ?? ??? ?System.out.println("The Parser called endDocument()!!!");
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void processingInstruction(String target,String data)
    ?? ?{
    ?? ??? ?System.out.println("The Parser called processingInstruction()!!!");
    ?? ??? ?System.out.println("target is {"+target+"}"+"data is {"+data+"}");
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void startPrefixMapping(String prefix,String uri)
    ?? ?{
    ?? ??? ?System.out.println("The Parser called startPrefixMapping()!!!");
    ?? ??? ?System.out.println("prefix is {"+prefix+"}uri is {"+uri+"}");
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void endPrefixMapping(String prefix)
    ?? ?{
    ?? ??? ?System.out.println("The Parser called endPrefixMapping()!!!");
    ?? ??? ?System.out.println("prefix is {"+prefix+"}");
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void startElement(String namespaceURL,String localName,String rawName,Attributes atts) throws SAXException
    ?? ?{
    ?? ??? ?System.out.println("The Parser called startElement()!!!");
    ?? ??? ?if(!namespaceURL.equals(""))
    ?? ??? ?{
    ?? ??? ??? ?System.out.println("nameSpaceURL is {"+namespaceURL+"}"+"rawName is {"+rawName+"}");
    ?? ??? ?}
    ?? ??? ?else
    ?? ??? ?{
    ?? ??? ??? ?System.out.println("There is not namespace");
    ?? ??? ?}
    ?? ??? ?System.out.println("localName is {"+localName+"}");
    ?? ??? ?for(int i=0;i<atts.getLength();i++)
    ?? ??? ?{
    ?? ??? ??? ?System.out.println("Attribute is {"+atts.getLocalName(i)+"}is {"+atts.getValue(i)+"}");
    ?? ??? ?}
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void endElement(String namespaceURL,String localName,String rawName) throws SAXException
    ?? ?{
    ?? ??? ?System.out.println("The Parser called endElement()!!!");
    ?? ??? ?System.out.println("localName is {"+localName+"}");
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void characters(char[] ch,int start,int end)
    ?? ?{
    ?? ??? ?String sss=new String(ch,start,end);
    ?? ??? ?System.out.println("The Parser called characters()!!!");
    ?? ??? ?System.out.println("characters is {"+sss+"}");
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void ignorableWhitespace(char[] ch,int start,int end) throws SAXException
    ?? ?{
    ?? ??? ?String sss=new String(ch,start,end);
    ?? ??? ?System.out.println("The Parser called ignorableWhitespace()!!!");
    ?? ??? ?System.out.println("ignorableWhitespace is {"+sss+"}");
    ?? ??? ?System.out.println("===============================");
    ? }
    ? public void skippedEntity(String name) throws SAXException
    ? {
    ? ?? ?System.out.println("The Parser called skippedEntity()!!!");
    ?? ??? ?System.out.println("skippedEntity {"+name+"}");
    ?? ??? ?System.out.println("===============================");
    ? }
    }
    class EHandlerClass1 implements ErrorHandler
    {
    ?? ?public void warning(SAXParseException spe) throws SAXException
    ?? ?{
    ?? ??? ?System.out.println("The Parser called warning()!!!!");
    ?? ??? ?System.out.println("Line is "+spe.getLineNumber());
    ?? ??? ?System.out.println("URI is "+spe.getSystemId());
    ?? ??? ?System.out.println("Message is "+spe.getMessage());
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void error(SAXParseException spe) throws SAXException
    ?? ?{
    ?? ??? ?System.out.println("The Parser called error()!!!!");
    ?? ??? ?System.out.println("Line is "+spe.getLineNumber());
    ?? ??? ?System.out.println("URI is "+spe.getSystemId());
    ?? ??? ?System.out.println("Message is "+spe.getMessage());
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void fatalError(SAXParseException spe) throws SAXException
    ?? ?{
    ?? ??? ?System.out.println("The Parser called fatalError()!!!!");
    ?? ??? ?System.out.println("Line is "+spe.getLineNumber());
    ?? ??? ?System.out.println("URI is "+spe.getSystemId());
    ?? ??? ?System.out.println("Message is "+spe.getMessage());
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    }

    class DTDHandlerClass1 implements DTDHandler //聲明DTDHandlerClass,此類實現DTDHandler接口
    {
    ?? ?public void notationDecl(String? name,String publicId,String systemId) throws SAXException
    ?? ?{
    ?? ??? ?//輸出符號的相關信息
    ?? ??? ?System.out.println("The Parser called notationDecl()!!!!");
    ?? ??? ?System.out.println("name is "+name);
    ?? ??? ?System.out.println("publicId is "+publicId);
    ?? ??? ?System.out.println("systemId is "+systemId);
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    ?? ?public void unparsedEntityDecl(String name,String publicId,String systemId,String notationName) throws SAXException
    ?? ?{
    ?? ??? ?//輸出不可分析實體的相關信息
    ?? ??? ?System.out.println("The Parser called unparsedEntityDecl()!!!!");
    ?? ??? ?System.out.println("name is "+name);
    ?? ??? ?System.out.println("publicId is "+publicId);
    ?? ??? ?System.out.println("systemId is "+systemId);
    ?? ??? ?System.out.println("notationName is "+notationName);
    ?? ??? ?System.out.println("===============================");
    ?? ?}
    }

    采用的xml文件為:second.xml
    <?xml version="1.0" encoding="gb2312"?>
    <!DOCTYPE employee_data [
    <!ELEMENT employee_inf (employee_data+)>
    <!ELEMENT employee_data (name,age,sex,address,E_mail,photo)>
    <!ELEMENT name (#PCDATA)>
    <!ELEMENT age (#PCDATA)>
    <!ELEMENT sex (#PCDATA)>
    <!ELEMENT address (#PCDATA)>
    <!ELEMENT E_mail (#PCDATA)>
    <!ELEMENT Photo EMPTY>
    <!NOTATION jpg SYSTEM "C:\windows\system32\mspaint.exe">
    <!ENTITY mm_photo SYSTEM "mm_photo.jpg" NDATA jpg>
    <!ATTLIST photo picture ENTITY #IMPLIED>
    <!ATTLIST photo sw_tool NOTATION (jpg) #IMPLIED>
    ]>
    <employee_inf>
    ?? <employee_data>
    ????? <name>馬連浩</name>
    ????? <age>24</age>
    ????? <sex>男</sex>
    ????? <address>大連交通大學</address>
    ????? <E_mail> mlh123caoer@tom.com</E_mail>
    ????? <photo picture="mm_photo" sw_tool="jpg"/>
    ?? </employee_data>
    </employee_inf>
    dos輸出效果為:
    D:\2000>javac ParseXMLDTD.java

    D:\2000>java ParseXMLDTD second.xml
    ParseuriFile!
    ===============================
    The Parser called setDocumentLocator()!!!
    ===============================
    The Parser called startDocument()!!!
    ===============================
    The Parser called notationDecl()!!!!
    name is jpg
    publicId is null
    systemId is file:///C:/windows/system32/mspa
    ===============================
    The Parser called unparsedEntityDecl()!!!!
    name is mm_photo
    publicId is null
    systemId is file:///D:/2000/mm_photo.jpg
    notationName is jpg
    ===============================
    The Parser called startElement()!!!
    There is not namespace
    localName is {employee_inf}
    ===============================
    The Parser called ignorableWhitespace()!!!
    ignorableWhitespace is {
    ?? }
    ===============================
    The Parser called startElement()!!!
    There is not namespace
    localName is {employee_data}
    ===============================
    The Parser called ignorableWhitespace()!!!
    ignorableWhitespace is {
    ????? }
    ===============================
    The Parser called startElement()!!!
    There is not namespace
    localName is {name}
    ===============================
    The Parser called characters()!!!
    characters is {馬連浩}
    ===============================
    The Parser called endElement()!!!
    localName is {name}
    ===============================
    The Parser called ignorableWhitespace()!!!
    ignorableWhitespace is {
    ????? }
    ===============================
    The Parser called startElement()!!!
    There is not namespace
    localName is {age}
    ===============================
    The Parser called characters()!!!
    characters is {24}
    ===============================
    The Parser called endElement()!!!
    localName is {age}
    ===============================
    The Parser called ignorableWhitespace()!!!
    ignorableWhitespace is {
    ????? }
    ===============================
    The Parser called startElement()!!!
    There is not namespace
    localName is {sex}
    ===============================
    The Parser called characters()!!!
    characters is {男}
    ===============================
    The Parser called endElement()!!!
    localName is {sex}
    ===============================
    The Parser called ignorableWhitespace()!!!
    ignorableWhitespace is {
    ????? }
    ===============================
    The Parser called startElement()!!!
    There is not namespace
    localName is {address}
    ===============================
    The Parser called characters()!!!
    characters is {大連交通大學}
    ===============================
    The Parser called endElement()!!!
    localName is {address}
    ===============================
    The Parser called ignorableWhitespace()!!!
    ignorableWhitespace is {
    ????? }
    ===============================
    The Parser called startElement()!!!
    There is not namespace
    localName is {E_mail}
    ===============================
    The Parser called characters()!!!
    characters is { mlh123caoer@tom.com}
    ===============================
    The Parser called endElement()!!!
    localName is {E_mail}
    ===============================
    The Parser called ignorableWhitespace()!!!
    ignorableWhitespace is {
    ????? }
    ===============================
    The Parser called startElement()!!!
    There is not namespace
    localName is {photo}
    Attribute is {picture}is {mm_photo}
    Attribute is {sw_tool}is {jpg}

    ===============================
    The Parser called endElement()!!!
    localName is {photo}
    ===============================
    The Parser called ignorableWhitespace()!!!
    ignorableWhitespace is {
    ?? }
    ===============================
    The Parser called endElement()!!!
    localName is {employee_data}
    ===============================
    The Parser called ignorableWhitespace()!!!
    ignorableWhitespace is {
    }
    ===============================
    The Parser called endElement()!!!
    localName is {employee_inf}
    ===============================
    The Parser called endDocument()!!!
    ===============================
    設計者:mlhcaoer 郵箱:mlh123caoer@tom.com QQ:215960358
    歡迎高手指導


    凡是有該標志的文章,都是該blog博主Caoer(草兒)原創,凡是索引、收藏
    、轉載請注明來處和原文作者。非常感謝。

    posted on 2006-04-20 08:45 草兒 閱讀(479) 評論(0)  編輯  收藏 所屬分類: 軟件構架
    主站蜘蛛池模板: 亚洲一欧洲中文字幕在线| 69国产精品视频免费| 亚洲精品人成网在线播放影院| 久久亚洲精品视频| 免费国产在线观看| 成人超污免费网站在线看| 免费看又黄又无码的网站| 久久嫩草影院免费看夜色| 狠狠入ady亚洲精品| 久久久国产亚洲精品| 亚洲综合无码一区二区三区| 伊人亚洲综合青草青草久热| 四虎永久免费影院| 妞干网在线免费视频| 亚洲黄色免费在线观看| 久久久免费的精品| 在线观看片免费人成视频无码| 黄床大片免费30分钟国产精品| 四虎一区二区成人免费影院网址| 亚洲AV无码国产剧情| 亚洲中文字幕久久无码| 国产精品亚洲精品| 亚洲国产日韩视频观看| 亚洲av无码片区一区二区三区| 亚洲欧洲综合在线| 亚洲精品**中文毛片| 亚洲永久中文字幕在线| 亚洲小说区图片区| 亚洲免费在线视频观看| 色噜噜亚洲男人的天堂| 最新国产成人亚洲精品影院| 亚洲av片不卡无码久久| 亚洲综合中文字幕无线码| 日韩亚洲国产综合高清| 亚洲精品国产首次亮相| 日日摸日日碰夜夜爽亚洲| 麻豆va在线精品免费播放| 一级a性色生活片久久无少妇一级婬片免费放 | 亚洲视频中文字幕| 亚洲国产精品无码久久SM| 亚洲爆乳精品无码一区二区三区|