Java and displaying a Document obect

Discussion in 'Java' started by Annorax, Nov 12, 2006.

  1. Annorax

    Annorax New Member

    Joined:
    Nov 12, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    QA Engineer
    Location:
    MA, USA
    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. :)
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    May be the object is not being created properly, debug with a try-catch block.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice