[jdom-interest] Small but irritating problem

Jan-Olof Hendig jan-olof.hendig at bredband.net
Mon Oct 25 12:28:50 PDT 2004

Hello folks,

Just to get it over with, I'm an XML newbie so keep the flame throwers away for a while please.

Today I upgraded from JDOM beta 9 to the current release. As they say, better late than never :) My code needed very few changes in order to compile, the constructor for XMLOutputter had changed but that was easy to fix. However when running the code, see below, a small incompatibility surfaced. 

with beta 9 the code below produced the following

<?xml version="1.0" encoding="UTF-8"?>

however with the current release I got

<?xml version="1.0" encoding="UTF-8"?>
<message xmlns:="">

as you can see the line containing the <message> tag suddenly includes the attribute 'xmlns:=""'

My question is this, how do I get rid of this xmlns attribute so that the message looks exactly like it did in beta 9?


Jan-Olof Hendig

/* --------------------- */

public class TestCase {
 protected static Document document;
 protected static Element rootElement;
 public static void main(String[] args) {
  rootElement = new Element("message");
  Element requestElement = new Element("request");
  Element onlyReturnOutDataElement = new Element("onlyreturnoutdata");
  document = new Document(rootElement);

  System.out.println(documentToString(document, true));
 public static String documentToString(Document doc, boolean fIndent) {
  JDOMSource domSource = new JDOMSource(doc);
  StringWriter stringWriter = new StringWriter();
  StreamResult result = new StreamResult(stringWriter);
  TransformerFactory tFactory = TransformerFactory.newInstance();
  try {
   Transformer transformer = tFactory.newTransformer();
   if (fIndent) {
       transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
       transformer.setOutputProperty(OutputKeys.INDENT, "no");
   transformer.transform(domSource, result);          
  catch (Exception e) {
  return stringWriter.toString();

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20041025/b1ffb1bd/attachment.htm

More information about the jdom-interest mailing list