How to Print a XML Document Object


XML & Web services: How to Print a XML Document Object

  1. How to Print a XML Document Object (1 messages)

    How to print an XML parsed Object.


    InputSource inputSource_ = new InputSource(new FileInputStream(XMLFileName));
    DOMParser domParser_ = new DOMParser();
    Document docObject_ = domParser_.getDocument();

    // now i want to print docObject_, how can i dothis?
    complete tree structure with values
  2. This is one common approach:

    DOMSource src = new DOMSource(docObject.getDocumentElement());
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    StreamResult result = new StreamResult(System.out); // output to this output stream
    transformer.transform(src, result);

    The transformer will perform the default "identity" transformation, resulting in the document being written as is to the output stream (in this case, System.out).