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

📄 myparser.java

📁 exemple for Document Object Model DOM
💻 JAVA
字号:
package mod鑜es;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;

public class MyParser extends DefaultHandler {
	private String nomFichierAparser;
	private int numeroLigne;
	@SuppressWarnings("unchecked")
	private Vector valeurChamps = new Vector();
	//le vecteur "autres" contiendra :
	// - le nom de la table et le noms des champs quand on parse le fichier.xml
	@SuppressWarnings("unchecked")
	private Vector autres = new Vector();
	//le vecteur "Typechamps" contiendra :
	// - le type des champs de la table quand on parse le sch閙a.
	@SuppressWarnings("unchecked")
	private Vector Typechamps = new Vector();
	
	/** Constructeur
	 * @param nomFichierAparser
	 */
	@SuppressWarnings("unchecked")
	public MyParser(String nomFichierAparser){
		this.nomFichierAparser = nomFichierAparser;
		numeroLigne = 0;
		valeurChamps = new Vector();
	}
	
	public void parsingFile(){
		try {
			XMLReader xr = XMLReaderFactory.createXMLReader();
			xr.setContentHandler(this);
			xr.setErrorHandler(this);
			FileReader r = new FileReader(this.nomFichierAparser);
			xr.parse(new InputSource(r));
		    }
		catch (IOException ex) {
			System.out.println("erreur d'ouverture de fichier");
		}
		catch (org.xml.sax.SAXException e) {
			System.out.println("erreur de parsing");
		}
	}
	
	
	////////////////////////////////////////////////////////////////////
	// Event handlers.
	////////////////////////////////////////////////////////////////////
	public void startDocument() {
		//System.out.println("Start document");
	}

	public void endDocument() {
		//System.out.println("End document");
	} 
	
 	@SuppressWarnings("unchecked")
	public void startElement(String uri, String localName,
 							 String qName,Attributes attributes) throws SAXException{
 		String unAttribut;
 		//String strReturn; 		
 		//strReturn = "|" + qName + "|";
 		//System.out.print(numeroLigne);   
 		for(int i = 0; i < attributes.getLength(); i++)
 		{
 			if(attributes.getLocalName(i)=="type"){
 				//on ajoute le type des champs qui ont 閠

⌨️ 快捷键说明

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