[jdom-interest] Losing Format And Indent
Narasimha Rao Nadella
nrnadella at rocketmail.com
Tue Mar 25 11:31:13 PST 2003
I have following code, in which tArrayElement.toString() will calls
upon itself recursively. tArrayElement is an Value Object which will
contain other value objects and they might contain other Objects.
Ex: Seller Sales Object Containing Buyer Objects, and Buyer Object
containing Address objects etc.
************************************
com.framework.vo.ResultVOBase[] valList =
(com.framework.vo.ResultVOBase[]) valueObj;
voFieldNode = new Element(fieldName+ "-Array");
voFieldNode.setAttribute(new Attribute("DataType", fieldtype));
voValueNode = new Element("Value");
Element voArrayElement;
for(int array_index =0; array_index < valList.length; array_index++)
{
Object tArrayElement = valList[array_index];
String sCurArrayItem = fieldName+ "-Array-"+array_index;
voArrayElement = new Element(sCurArrayItem);
if(tArrayElement.toString() == null)
{
voArrayElement.addContent("Null");
}
else
{
//voArrayElement.addContent(serializer.outputString(new
Element(tArrayElement.toString())));
voArrayElement.addContent(serializer.escapeElementEntities(tArrayElement.toString()));
}
voValueNode.addContent(voArrayElement);
}
voFieldNode.addContent(voValueNode);
dataNode.addContent(voFieldNode);
************************************
The first time it calls i get Content well formatted
<Value>24<Value>.
But when it goes into loop...it lost its formatting and Indenting.
1st Pass: amp;lt;Valueamp;gt;24amp;lt;/Valueamp;gt;
2nd Pass: &amp;lt;Value&amp;gt;24&amp;lt;/Value&amp;gt;
I am using
XMLOutputter serializer = new XMLOutputter(" ", true,
"UTF-8");
serializer.setNewlines(true);
serializer.setIndent(true);
serializer.setIndentSize(4);
I am new to XML and i might be missing something here... I would be
glad if anyone can give me suggestion so that i can retain format.
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
More information about the jdom-interest
mailing list