i am writnig a simple program that get a string and translate that to a xml document but it dont show value of content i set it show null!
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;
}
}
You are calling
getTextContenton a document node. This always results in a null value as you can read in the api docs:http://download.oracle.com/javase/1.5.0/docs/api/org/w3c/dom/Node.html#getTextContent()
You will get the value if you call
dc.getFirstChild().getTextContent()(after appending the element to the document), because now you are callinggetTextContenton an element node.