How to Print XML Object

Dear all,

If I want to print the xmlObject Content before I insert it to XML DB, the Print out result should like:

So, what should I do?
Following is my xmlObject DataType:

TXMLObject xmlObject = TXMLObject.newInstance( TDOMObjectModel.getInstance());

You can use the writeTo() method of the TXMLObject:


Thank you for your idea!!
However, it seems that it only output a single line for whole xml document. What I want is to output like a “tree-like” format. So, do you have any new suggestion?

Yes - you can use the older API’s static printTree() method like this:

import com.softwareag.tamino.api.dom.TaminoClient; 
Element myElement = (Element) xmlObject.getElement();

The older API is delivered in file “TaminoClient.jar”.

The node content can be displayed, but it return some abnormal character instead of tag “<” “>”, how can I solve this?

You probably can’t change this - the method prints a tree using plain text and ansi characters which represent the tree structure. If you want a more traditional view of your xml, try using this code (which employs xerces):

import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
// Serialize the document
Document mydoc = (Document) xmlObject.getDocument();
OutputFormat format = new OutputFormat(myDoc);
XMLSerializer serializer = new XMLSerializer(System.out, format);

If this doesn’t deliver exactly what you need, you could try using xalan to apply a stylesheet and print the result. Then you would have complete control over the output appearance.

I got it.
Thank a lot!!