<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 草兒 閱讀(485) 評論(0)  編輯  收藏 所屬分類: 軟件構架
    主站蜘蛛池模板: 国产成人精品免费视| 亚洲综合欧美色五月俺也去| 亚洲欧洲一区二区| www成人免费视频| 亚洲?V无码乱码国产精品| 亚洲va中文字幕| 亚洲精品无码日韩国产不卡av| 182tv免费视视频线路一二三| 亚洲成在人天堂在线| 久久99热精品免费观看牛牛| 亚洲国产美国国产综合一区二区 | 久久精品国产亚洲AV无码偷窥| 免费无码中文字幕A级毛片| 久久久久久久久亚洲 | 中文字幕视频免费| 亚洲成在人线电影天堂色| 国产精品成人免费福利| 国产精品高清视亚洲一区二区| 最近中文字幕无吗高清免费视频| 亚洲精品自偷自拍无码| 亚洲福利精品一区二区三区| 两个人看www免费视频| 午夜亚洲AV日韩AV无码大全| 5555在线播放免费播放| 亚洲精品又粗又大又爽A片| 亚洲成A人片在线观看中文| 精品视频一区二区三区免费| 亚洲小说图片视频| 日本人的色道www免费一区| 亚洲成人国产精品| 久青草视频97国内免费影视| 57PAO成人国产永久免费视频| 亚洲精品乱码久久久久久V| 精品国产人成亚洲区| 67pao强力打造高清免费| 亚洲国产日韩a在线播放| 亚洲中文字幕无码久久综合网| 69精品免费视频| 一本久久免费视频| 18gay台湾男同亚洲男同| www.亚洲一区|