[jdom-interest] XMLOutputter - setExpandEmptyElements(true) not functioning properly.

kendrick at us.ibm.com kendrick at us.ibm.com
Tue Sep 19 10:13:44 PDT 2000


I am seeing my empty elements (content of an empty String) outputted in the
shorthand format (<tagName />) even after I issued
setExpandEmptyElements(true).  I traced the code in XMLOutputter.
printElement() to:

     ...
     if (empty) {
          // Simply close up
          if (!expandEmptyElements) {
               out.write(" />");
          } else {
               out.write("></");
               out.write(element.getQualifiedName());
               out.write(">");
          }
          maybePrintln(out);
     } else if (stringOnly) {
          // Print the tag  with String on same line
          // Example: <tag name="value">content</tag>
          // Also handle "" being added to content
          String elementText = element.getText();
          if ((elementText != null) && (!elementText.equals(""))) {
               out.write(">");
               out.write(escapeElementEntities(element.getText()));
               out.write("</");
               out.write(element.getQualifiedName());
               out.write(">");
          } else {
==========>
== here ==>         out.write(" />");
==========>
          }
          maybePrintln(out);
     } else {
     ...

Apparently the check for expandEmptyElements needs to occur here as well.

Sincerely,
Shannon

IBM e-business Integration Services
3200 Windy Hill Road - Atlanta, GA 30332 - WG06B
Phone: 770-835-7672 T/L 445   FAX: 770-835-6479
Internet: kendrick at us.ibm.com





More information about the jdom-interest mailing list