?? myparser.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 + -