| Beitrag 7 von 47 (15%) | Antworten Beitrag schreiben | Anfang zurück weiter Ende |
|
|
Hallo ,
weiss jemand warum diese programm nicht funktioniert.
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Node;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
public class dom1 {
public static void main (String args[]) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse("weblinks.xml");
NodeList KnotenListe = document.getElementsByTagName("url");
int anzahl = KnotenListe.getLength();
for (int i = 0; i < anzahl; i++) {
System.out.println(KnotenListe.item(i).getFirstChild().getNodeValue());
}
}
}
weblinks.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblinks SYSTEM "weblinks.dtd">
<weblinks>
<eintrag id="0">
<kategorie>edv</kategorie>
<url>http://www.w3.org</url>
<notiz>W3-Konsortium</notiz>
<notiz>Technische Referenz</notiz>
</eintrag>
<eintrag id="1">
<kategorie>phy</kategorie>
<url>http://www.cern.ch</url>
<notiz>Europaeisches Kernforschungszentrum</notiz>
<notiz>Aktuelles zur Hochenergiephysik</notiz>
<notiz>Materialien zur Elementarteilchenphysik<notiz>
</eintrag>
...
</weblinks>
das Programm bringt mir folgende fehlermeldung :
at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3339)
at org.apache.crimson.parser.Parser2.externalParameterEntity(Parser2.java:3027)
at org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1314)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:623)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:333)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
at beispiel.dom1.main(dom1.java:18)
ich werde für euere Hilfe dankbar
Gruss
Essi