我寫了一個簡單的程序,它獲取一個字符串並將其轉換爲一個xml文檔,但它不顯示內容的價值,我將它設置爲顯示null!java中xml文檔的問題
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class Server {
/**
* @param args
*/
public static void main(String[] args) {
Server server=new Server();
Document dc=server.stringToDocument("f0");
System.out.println(dc.getTextContent());
}
public org.w3c.dom.Document stringToDocument(String order)
{
org.w3c.dom.Document result=null;
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
try{
DocumentBuilder db=dbf.newDocumentBuilder();
result=db.newDocument();
Element el=result.createElement("ORDER");
el.setTextContent(order);
}
catch (Exception e) {
System.out.println("DB in line 1418 exception");
}
return result;
}
}
我這樣做,現在它的作品..感謝很多..我接受你的答案 – sahera