1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
package com.lecture.xml;
import org.xml.sax.*;
import org.xml.sax.helpers.LocatorImpl;
import java.util.Vector;
public class XmlLangUtil implements ContentHandler {
String lang;
String element = "";
Vector vec_element = new Vector();
boolean bool = false;
int i = 0;
public XmlLangUtil(String langx) {
super();
locator = new LocatorImpl();
lang = langx;
}
public void setDocumentLocator(Locator value) {
locator = value;
}
public void startElement(String nameSpaceURI, String localName, String rawName, Attributes attributs)
throws SAXException {
element = localName;
if(element.equals(lang))
bool = true;
}
public void characters(char[] ch, int start, int end) throws SAXException {
if(bool){
String str = new String(ch, start, end);
vec_element.addElement(str);
bool = false;
}
}
public void endDocument() throws SAXException {
XmlLang.res = vec_element;
}
public void endElement(String nameSpaceURI, String localName, String rawName) throws SAXException {}
public void startDocument() throws SAXException {}
public void startPrefixMapping(String prefix, String URI) throws SAXException {}
public void endPrefixMapping(String prefix) throws SAXException {}
public void ignorableWhitespace(char[] ch, int start, int end) throws SAXException {}
public void processingInstruction(String target, String data) throws SAXException {}
public void skippedEntity(String arg0) throws SAXException {}
private Locator locator;
} |
Partager