Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Java and displaying a Document obect (http://www.go4expert.com/forums/java-displaying-document-obect-t1869/)

Annorax 13Nov2006 04:54

Java and displaying a Document obect
 
I have a method which writes an XML to an object of type Document, as follows:

Document oDoc = new DocumentImpl();

Element rootElement = oDoc.createElement("ROOT_ELEMENT_NAME");
rootElement.setAttribute("ATTRIBUTE_1", "VALUE_OF_ATTRIBUTE");
rootElement.setAttribute("ATTRIBUTE_2", "VALUE_OF_ATTRIBUTE");
rootElement.setAttribute("ATTRIBUTE_3", "VALUE_OF_ATTRIBUTE");
rootElement.setAttribute("ATTRIBUTE_4", "VALUE_OF_ATTRIBUTE");
oDoc.appendChild(rootElement);

Element element_1 = oDoc.createElement("CHILD_ELEMENT_1");
element_1.setAttribute("ATTRIBUTE_1", "VALUE_OF_ATTRIBUTE");
element_1.setAttribute("ATTRIBUTE_2", "VALUE_OF_ATTRIBUTE");
element_1.setAttribute("ATTRIBUTE_3", "VALUE_OF_ATTRIBUTE");
element_1.setAttribute("ATTRIBUTE_4", "VALUE_OF_ATTRIBUTE");
rootElement.appendChild(element_1);

Element element_2 = oDoc.createElement("CHILD_ELEMENT_2");
element_2.setAttribute("ATTRIBUTE_1", "VALUE_OF_ATTRIBUTE");
element_2.setAttribute("ATTRIBUTE_2", "VALUE_OF_ATTRIBUTE");
element_2.setAttribute("ATTRIBUTE_3", "VALUE_OF_ATTRIBUTE");
element_2.setAttribute("ATTRIBUTE_4", "VALUE_OF_ATTRIBUTE");
rootElement.appendChild(element_2);

Element element1_1 = oDoc.createElement("CHILD_ELEMENT_1_1");
element1_1.setAttribute("ATTRIBUTE_1", "VALUE_OF_ATTRIBUTE");
element1_1.setAttribute("ATTRIBUTE_2", "VALUE_OF_ATTRIBUTE");
element1_1.setAttribute("ATTRIBUTE_3", "VALUE_OF_ATTRIBUTE");
element1_1.setAttribute("ATTRIBUTE_4", "VALUE_OF_ATTRIBUTE");
element_1.appendChild(element1_1);

return oDoc;

I want to print the object oDoc to the screen, but every time I do, using:

System.out.println(oDoc);

It returns as this:

[#document: null]

My theory is that there's some method of Document that will display the contents of the object on the screen. Can someone please tell me what that is? Thanks for any help. :)

pradeep 13Nov2006 11:34

Re: Java and displaying a Document obect
 
May be the object is not being created properly, debug with a try-catch block.


All times are GMT +5.5. The time now is 19:08.