[jdom-interest] XMLOutputter
Alex Rosen
arosen at novell.com
Thu Feb 12 07:49:21 PST 2004
XMLOutputter lets you specify whether you want it to add newlines and
indents. Did you have a look at the JavaDoc?
Alex
>>> "J. Albers" <jalbers at cs.uu.nl> 2/12/2004 7:46:11 AM >>>
Hi,
I got a bit of a problem, i'm using XMLOutputter to let my application
put
some manipulated XML elements in the output in an XML format. But the
problem is i just get it in 1 line like:
<?xml version="1.0" encoding="UTF-8"?>
<linux><gui3></gui3><window-manager></window
manager><type>java</type><name>Enlightenment</name><version3>0.16.2</version
3><gui></gui><window-manager></window
manager><name>Enlightenment</name><version1>0.16.2</version1></linux>
All info i need is there, but not formatted right... it should be :
<linux>
<gui3>
<window-manager>
<type>java</type>
<name>Enlightenment</name>
<version3>0.16.2</version3>
</window-manager>
</gui3>
<gui>
<window-manager bla="2">
<name>Enlightenment</name>
<version1>0.16.2</version1>
</window-manager>
</gui>
</linux>
Anyone here know what's wrong?
Thanks, Joachim.
----------------------------------------------------------------------------
------
private static void compareChildren(Element element1, Element
element2,
Document doc, Element root)
{
List children1 = element1.getChildren();
List children2 = element2.getChildren();
if(children1.size() > children2.size())// lijst 2 moet de grootste
zijn.
{
children1 = element2.getChildren();
children2 = element1.getChildren();
}
if(children1.size() > 0 && children2.size() > 0)
System.out.println("Elements are "+ getSamePercentage(children1,
children2)+" % the same.");
//Element child = new Element("shit");
for (int i=0; (i < (children1.size())); i++)
{
if((children1.get(i).toString()).equals(children2.get(i).toString()))
{
System.out.println(children1.get(i)+" and1 "+children2.get(i)+"
are the
same.");
//printStuff((Element)children1.get(i), doc, root);
Element childname = (Element)children1.get(i);
Element child = new Element(""+childname.getName());
String text = childname.getTextNormalize();
//if((text != null) && (!text.equals(""))){
child.addContent(text);
//}
root.addContent(child);
compareChildren(((Element) children1.get(i)), ((Element)
children2.get(i)), doc, root);
}
else
{
for (int j=1; (j < (children2.size()));j++)
{
if(
(children1.get(i).toString()).equals((children2.get(j).toString())))
{
System.out.println(children1.get(i)+" and2 "+children2.get(j)+"
are the
same.");
//printStuff((Element)children1.get(i), doc, root);
Element childname = (Element)children1.get(i);
Element child = new Element(""+childname.getName());
String text = childname.getTextNormalize();
// if((text != null) && (!text.equals(""))){
child.addContent(text);
//}
root.addContent(child);
compareChildren(((Element) children1.get(i)), ((Element)
children2.get(j)),doc, root);
}
}
}
}
try{
result.output.setText(new XMLOutputter().outputString(doc));
}
catch (Exception e) {e.printStackTrace();}
}
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
More information about the jdom-interest
mailing list