Eine Klasse DocExt ist abgeleitet von org.jdom.Document, wie kann ich eine XML-Datei in DocExt laden?
Folgendes habe ich schon ausprobiert, funktioniert aber nicht:
1. (dummer) Versuch über Cast Superklasse->Subklasse, liefert ClassCastException
SAXBuilder b = new SAXBuilder(false);
DocExt ret = null;
ret = (DocExt)b.build(xml);
public class DocExt extends Document { ... }
2. Versuch über Konstruktor Document(java.util.List content), liefert:
org.jdom.IllegalAddException: The element "..." could not be added as the root of the document: The Content already has an existing parent document at org.jdom.ContentList.add(ContentList.java:214)
SAXBuilder b = new SAXBuilder(false);
DocExt ret = null;
ret = new DocExt( b.build(xml).getContent() );
public class DocExt extends Document {
protected DocExt(List content) {
super( content );
}
}
Wie geht das? Vielen Dank
Folgendes habe ich schon ausprobiert, funktioniert aber nicht:
1. (dummer) Versuch über Cast Superklasse->Subklasse, liefert ClassCastException
SAXBuilder b = new SAXBuilder(false);
DocExt ret = null;
ret = (DocExt)b.build(xml);
public class DocExt extends Document { ... }
2. Versuch über Konstruktor Document(java.util.List content), liefert:
org.jdom.IllegalAddException: The element "..." could not be added as the root of the document: The Content already has an existing parent document at org.jdom.ContentList.add(ContentList.java:214)
SAXBuilder b = new SAXBuilder(false);
DocExt ret = null;
ret = new DocExt( b.build(xml).getContent() );
public class DocExt extends Document {
protected DocExt(List content) {
super( content );
}
}
Wie geht das? Vielen Dank