xxx9834; Hello again xxx9835; ;)
i try to parse a XML string bo doing the following:
PHP Code:
private void parseDocument() {
//get a factory
SAXParserFactory spf = SAXParserFactory.newInstance();
try {
//get a new instance of parser
SAXParser sp = spf.newSAXParser();
//parse the file and also register this class for call backs
sp.parse("employees.xml", this);
}catch(SAXException se) {
se.printStackTrace();
}catch(ParserConfigurationException pce) {
pce.printStackTrace();
}catch (IOException ie) {
ie.printStackTrace();
}
}
PHP Code:
//Event Handlers
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
//reset
tempVal = "";
if(qName.equalsIgnoreCase("Employee")) {
//create a new instance of employee
tempEmp = new Employee();
tempEmp.setType(attributes.getValue("type"));
}
}
public void characters(charxxx91;xxx93; ch, int start, int length) throws SAXException {
tempVal = new String(ch,start,length);
}
public void endElement(String uri, String localName,
String qName) throws SAXException {
if(qName.equalsIgnoreCase("Employee")) {
//add it to the list
myEmpls.add(tempEmp);
}else if (qName.equalsIgnoreCase("Name")) {
tempEmp.setName(tempVal);
}else if (qName.equalsIgnoreCase("Id")) {
tempEmp.setId(Integer.parseInt(tempVal));
}else if (qName.equalsIgnoreCase("Age")) {
tempEmp.setAge(Integer.parseInt(tempVal));
}
}
PHP Code:
public class Employee {
private String type = "";
private String name = "";
private String id = "";
private String age = "";
public void setType(String _type) {
type = _type;
}
public void setName(String _name) {
name = _name;
}
public void setId(String _id) {
id = _id;
}
public void setAge(String _age) {
age = _age;
}
}
My problem is, that the compiler will not do wat i want ;)
Quote:
Originally Posted by compiler
Symbol : method parse(java.lang.String,Project1)
location: class net.rim.device.api.xml.parsers.SAXParser
sp.parse("employees.xml", this);
|
i also have these one here at the begining of my source:
PHP Code:
import net.rim.device.api.xml.parsers.SAXParserFactory;
import net.rim.device.api.xml.parsers.*;
import net.rim.device.api.xml.parsers.SAXParser.*;
So whats wrong?
what do i need to change if i want to parse a XML-string instead of a XML-File?
thanks hibbert