⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplecontenthandler.java

📁 exemple for Document Object Model DOM
💻 JAVA
字号:
package simple;

import org.xml.sax.*;
import org.xml.sax.helpers.LocatorImpl;


public class SimpleContentHandler implements ContentHandler {


        public SimpleContentHandler() {
                super();
                 new LocatorImpl();
        }
        public void setDocumentLocator(Locator value) {
        }

        public void startDocument() throws SAXException {
                System.out.println("Debut de l'analyse du document");
        }
        public void endDocument() throws SAXException {
                System.out.println("Fin de l'analyse du document" );
        }

        public void startPrefixMapping(String prefix, String URI) throws SAXException {
                System.out.println("Traitement de l'espace de nommage : " + URI + ", prefixe choisi : " + prefix);
        }

        public void endPrefixMapping(String prefix) throws SAXException {
                System.out.println("Fin de traitement de l'espace de nommage : " + prefix);
        }

        public void startElement(String nameSpaceURI, String localName, String rawName, Attributes attributs) throws SAXException {
                System.out.println("Ouverture de la balise : " + localName);

                if ( ! "".equals(nameSpaceURI)) { 
                        System.out.println("  appartenant a l'espace de nom : "  + nameSpaceURI);
                }

                System.out.println("  Attributs de la balise : ");

                for (int index = 0; index < attributs.getLength(); index++) { 
                        System.out.println("     - " +  attributs.getLocalName(index) + " = " + attributs.getValue(index));
                }
        }

        public void endElement(String nameSpaceURI, String localName, String rawName) throws SAXException {
                System.out.print("Fermeture de la balise : " + localName);

                if ( ! "".equals(nameSpaceURI)) { 
                        System.out.print("appartenant a l'espace de nommage : " + localName);
                }

                System.out.println();
        }

        public void characters(char[] ch, int start, int end) throws SAXException {
                System.out.println("#PCDATA : " + new String(ch, start, end));
        }

        public void ignorableWhitespace(char[] ch, int start, int end) throws SAXException {
                System.out.println("espaces inutiles rencontres : ..." + new String(ch, start, end) +  "...");
        }

        public void processingInstruction(String target, String data) throws SAXException {
                System.out.println("Instruction de fonctionnement : " + target);
                System.out.println("  dont les arguments sont : " + data);
        }

        public void skippedEntity(String arg0) throws SAXException {
               }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -