Hi,

I couldn't reprocude your problem. The following code generates the correct XML:

Document doc = DocumentFactory.getInstance().createDocument();
Element grandFather = doc.addElement("grandfather");
Element parent1 = grandFather.addElement("parent");
Element child1 = parent1.addElement("child1");
Element child2 = parent1.addElement("child2");
child2.setText("test");
Element parent2 = grandFather.addElement("parent");
Element child3 = parent2.addElement("child3");
child3.setText("test");
StringWriter buffer = new StringWriter();
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(buffer, format);
writer.write(doc);
String xml = buffer.toString();


could you try the code above to check if it works for you as well?

regards,
Maarten

Swati Vakharia wrote:

I have noticed something unusual when creating an xml document with
dom4j. Some of my tags seem to disappear after empty tags and I wanted
to know if anyone else has experienced this. For example, if the
following is how its SUPPOSE to look:

<grandparent>
  <parent>
     <child1>test</child1>
     <child2>test</child1>
  </parent>
  <parent>
      <child3>test</child3>
   </parent>
</grandparent>

the following is generated if child1 is empty and child2 has a value

<grandparent>
  <parent>
     <child1/>
  </parent>
  <parent>
      <child3>test</child3>
   </parent>
</grandparent>

You can see that child2 is completely ignored even though it shouldnt
be. WHY!?!. if anyone else has encountered this please let me know the
work around. Thanks for your help in advanced.


------------------------------------------------------- This SF.Net email is sponsored by: Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux. http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user







-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to