[jdom-interest] org.jdom.output.XMLOutputter in JDOM b8

Sullivan, Sean C - MLG Sullivan.Sean at menlolog.com
Tue Jul 2 11:54:15 PDT 2002


I am using JDOM b8

My question is in regard to org.jdom.output.XMLOutputter

First, I subclassed XMLOutputter

Here is my implementation:

/////////////////////////////////

package foobar;

import org.jdom.output.XMLOutputter;

class CustomXMLOutputter extends XMLOutputter
{
	public CustomXMLOutputter() 
	{
		super();
	}
	public java.lang.String escapeElementEntities(java.lang.String str)
	{
		return str;
	}
}


/////////////////////////////////



Here is how I am trying to use the XMLOutputter:


///////////////// Foo.java ////////////////////
Public class Foo
{
	public String toString()
	{
		CustomXMLOutputter outputter = new CustomXMLOutputter();
		outputter.setNewlines(true);
		outputter.setLineSeparator("\r\n");
		outputter.setIndent("   ");
		outputter.setIndent(true);
		String strResult =
outputter.outputString(this.getXMLAsString());
		return strResult;
 	}

}

///////////////// end Foo.java ////////////////////


Question:


The CustomXMLOutputter is not formatting the code correctly.

I am expecting the resulting string to have a "pretty" layout
where the elements are on separate lines and have indentation.

Unfortunately, the String that is returned contains 2 lines:

<?xml version="1.0" encoding="UTF-8"?>
<XRequest><Common><RequestType>Hello</RequestType></Common></XRequest>


How the elements are formatted this way?

Is this a bug in JDOM or a bug in my code?

-Sean





More information about the jdom-interest mailing list