请问我的startParse方法返回的是Document对象,
Document返回的是这个,
[Document:  No DOCTYPE declaration, Root is [Element: <root/>]]
下面这个类我里面的内容我写进Document里了,但是我在别的类调用startParse方法的返回的时候没有加进去
class Callback extends HTMLEditorKit.ParserCallback 
public Document startParse(String sHtml) {
Document doc=new Document();
try {
Element root=new Element("root");
doc.setRootElement(root);
ParserDelegator parser = new ParserDelegator();
HTMLEditorKit.ParserCallback callback = new Callback(root);

parser.parse(new StringReader(sHtml), callback, true);



XMLOutputter outp = new XMLOutputter();//用于输出jdom 文档
Format format=Format.getPrettyFormat(); //格式化文档
format.setEncoding("GBK"); //由于默认的编码是utf-8,中文将显示为乱码,所以设为gbk
outp.setFormat(format);
try {
outp.output(doc,System.out);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //输出文档
} catch (Exception e) {
e.printStackTrace();
}
return doc;
}
class Callback extends HTMLEditorKit.ParserCallback {
private Document doc;
private Element root;
public Callback(Document _doc){
this.doc=_doc;

}
public Callback(Element _root){
this.root=_root;
}
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
if (t.equals(HTML.Tag.TABLE)) {
String src = (String) a.getAttribute(HTML.Attribute.NAME);
System.out.println("No." + count + "   IMG   src=" + src);
count++;
}
if (t.equals(HTML.Tag.INPUT)) {
String type = (String) a.getAttribute(HTML.Attribute.TYPE);
System.out.println("No." + count + "   input   type=" + type);
Element table=(Element)root.getChildren().get(0);
Element tr=new Element("tr");
Element td=new Element("td");
String id = (String) a.getAttribute(HTML.Attribute.ID);
for(int i=0;i<table.getContentSize();i++){
tr=(Element)table.getChildren().get(i);
for(int j=0;j<tr.getContentSize();j++){
td=(Element)tr.getChildren().get(j);
Element input=new Element("input");

if(type==null && id!=null){
if(id.equals(td.getAttributeValue("id"))){
td.addContent(input);
input.setAttribute("id",id);
input.setAttribute("type","text");
input.setAttribute("size","10");
if(a.getAttribute(HTML.Attribute.WIDTH)!=null){
input.setAttribute("width",a.getAttribute(HTML.Attribute.WIDTH).toString());
}else{
input.setAttribute("width","");
}
if(a.getAttribute(HTML.Attribute.STYLE)!=null){
input.setAttribute("style",a.getAttribute(HTML.Attribute.STYLE).toString());
}else{
input.setAttribute("style","text-align:left");
}
if(a.getAttribute(HTML.Attribute.VALUE)!=null){
input.setAttribute("value",a.getAttribute(HTML.Attribute.VALUE).toString());
}else{
input.setAttribute("value","");
}
if(a.getAttributeCount()>=7 && a.getAttribute(HTML.Attribute.VALUE)!=null){
input.setAttribute("readOnly","true");///????
}
}

}
}
}
count++;
}
} public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
if (t.equals(HTML.Tag.TABLE)) {
Element table=new Element("table");
root.addContent(table);
table.setAttribute("id",a.getAttribute(HTML.Attribute.ID).toString());
}
if(t.equals(HTML.Tag.TR)){
Element tr=new Element("tr");
String id=(String)a.getAttribute(HTML.Attribute.ID);
Element table=(Element)root.getChildren().get(0);
table.addContent(tr);
tr.setAttribute("id",id);
count++;
}
if (t.equals(HTML.Tag.TD)) {
Element table=(Element)root.getChildren().get(0);
Element tr=new Element("tr");
Element td=new Element("td");
String id = (String) a.getAttribute(HTML.Attribute.ID);
for(int i=0;i<table.getContentSize();i++){
td=new Element("td");
tr=(Element)table.getChildren().get(i);
if(id!=null ){
String str=id.substring(3,4);
if(str.equals(tr.getAttributeValue("id"))){
tr.addContent(td);
td.setAttribute("id",id);
}
}
}
System.out.println("No." + count + "   td   id=" + id);
count++;
}

} private int count = 1;
}