我幾個星期前寫了一個可用的XML-Saxparser。出於某種原因,我不知道爲什麼,它不再工作了,我想不出我在這些課上做了什麼。 當我查看調試器時,最後一件工作是URL url = new URL("http://hammerman.bplaced.net/Objekteingabe1.xml");
SAX-Parser拋出UnknownHostException
行xr.parse(new InputSource(url.openStream()));
似乎拋出IOException。 catch子句中的「e」的詳細信息顯示爲「UnknownHostException」或「Host is unolved」:...「stackTrace:null。
正如我所說,我真的不知道發生了什麼,所以我認爲我做了一個愚蠢的misstake某處或刪除了一行。但我現在搜索了幾個小時,我找不到它。 希望有人能幫助我。
非常感謝。 費邊
我Readerhelper看起來如下
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
handler = new Dokukmentenhandler();
xr.setContentHandler(handler);
URL url = new URL("http://hammerman.bplaced.net/Objekteingabe1.xml");
xr.parse(new InputSource(url.openStream()));
// Textobjekte = handler.Textobjekte;
// Phasen_anzahl = handler.Phasen_Counter;
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
和我的處理程序
@Override
public void startDocument() throws SAXException
{
}
@Override
public void startElement(String namespaceURI, String localName, String tagName, Attributes attributes) throws SAXException
{
// lege ein erstes dData objekt an
if (localName.equals("tData")) {
aktuell = new Textobjekt();
// damit das objekt existiert
currentVal = "";
}
// alle 4 Sensorarten werden abgefangen
if (localName.equals("Realer_Sensor")) {
realerSensor = true;
op = new Option();
}else if (localName.equals("Normalverteilung")) {
normalverteilung = true;
op = new Option();
op.Sensor_name= "Normalverteilung";
}else if (localName.equals("Bernoulliverteilung")) {
bernoulli = true;
op = new Option();
op.Sensor_name= "Bernoulliverteilung";
}else if (localName.equals("Gleichverteilung")) {
gleichverteilung = true;
op = new Option();
op.Sensor_name= "Gleichverteilung";
}
}
@Override
public void endElement(String namespaceURI, String localName, String tagName) throws SAXException
{
if (localName.equals("Variablen_Name")) {
aktuell = new Textobjekt();
aktuell.Variablenname = currentVal;
Textobjekte.add(aktuell);
}else if (localName.equals("Phasenanzahl")) {
Phasen_Counter = Integer.parseInt(currentVal);
}else if (localName.equals("Initialwert")) {
aktuell.Initialwert = Float.parseFloat(currentVal);
}
// alle 4 Sensorarten werden abgefangen, die booleans geschlossen und die optionen hinzugefuegt
else if (localName.equals("Realer_Sensor")) {
realerSensor = false;
aktuell.Optionenliste.add(op);
}else if (localName.equals("Normalverteilung")) {
normalverteilung = false;
aktuell.Optionenliste.add(op);
}else if (localName.equals("Bernoulliverteilung")) {
bernoulli = false;
aktuell.Optionenliste.add(op);
}else if (localName.equals("Gleichverteilung")) {
gleichverteilung = false;
aktuell.Optionenliste.add(op);
}
else if (localName.equals("Sensor_Name")) {
op.Sensor_name = currentVal;
}
else if (localName.equals("Parameter")) {
if (realerSensor) {
float f = Float.parseFloat(currentVal);
op.list.add(f);
}
}else if (localName.equals("Nu")) {
if (normalverteilung) {
float f = Float.parseFloat(currentVal);
op.list.add(f);
}
}else if (localName.equals("sigma")) {
if (normalverteilung) {
float f = Float.parseFloat(currentVal);
op.list.add(f);
}
}
else if (localName.equals("Pi")) {
if(bernoulli){
float f = Float.parseFloat(currentVal);
op.list.add(f);
}
}
else if (localName.equals("Untere_Wertegrenze")) {
if (gleichverteilung) {
float f = Float.parseFloat(currentVal);
op.list.add(f);
}
}
else if (localName.equals("Obere_Wertegrenze")) {
if (gleichverteilung) {
float f = Float.parseFloat(currentVal);
op.list.add(f);
}
}
// Ende der Optionenliste
else if (localName.equals("Eventvorkommen")) {
aktuell.Eventvorkommen = currentVal;
}
else if (localName.equals("Bezugsart")) {
aktuell.Bezugsart = currentVal;
}
else if (localName.equals("Eventart")) {
aktuell.Eventart = currentVal;
}
else if (localName.equals("Ueberschreitungswert")) {
float f = Float.parseFloat(currentVal);
aktuell.Ueberschreitungswert = f;
}
else if (localName.equals("Auswirkung")) {
float f = Float.parseFloat(currentVal);
aktuell.Auswirkung = f;
}
else if (localName.equals("Objektname")) {
re = new Referenz();
re.Objektname = currentVal;
}
else if (localName.equals("Referenzwert")) {
float f = Float.parseFloat(currentVal);
re.Referenzwert = f;
aktuell.referenzliste.add(re);
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if (length > 0) {
currentVal = new String(ch,start,length);
}
}
}
你是對的......由於一些愚蠢的原因,我刪除了我的項目中的xsd文件。刪除「xsi:noNamespaceSchemaLocation =」Objekteingabe.xsd「解決了我的問題!驗證並不重要!非常感謝Heiko! – fabian 2011-04-19 22:48:54