[jdom-interest] RE: Whitespace

Bradley S. Huffman hip at cs.okstate.edu
Mon Jan 19 16:10:16 PST 2004


Instead of

    XMLOutputter outputter = new XMLOutputter("  ", true);
    outputter.output(doc, System.out);

just use

    XMLOutputter outputter = new XMLOutputter();
    outputter.output(doc, System.out);

Brad

"Jeremy Whitlock" writes:

> JDOM,
> 	I've found the problem and it happens to be with JDOM itself.
> If you read in an XML document into JDOM and then output it to a new
> file without modifying the structure of the XML Document while in JDOM,
> it adds extra characters to the file.  Here's an example:
> 
> Here is my document as is on file:
> 
> <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> <!--DBPirate Configuration File-->
> <dbpirate>
>    <connections>
>       <connection>=20
>          <name>Oracle</name>
>          <user>cbuser</user>
>          <password>cbpass</password>
>          <hostname>localhost</hostname>
>          <port>1521</port>
>          <timestamp>345678</timestamp>
>          <class>org.mysql.jdbc.Driver</class>
>          <url>jdbc:mysql at localhost:3306:cookbook:cbuser:cbpass</url>
>          <sid>cookbook</sid> =20
>       </connection>
>       <connection>=20
>          <name>MySQL</name>
>          <user>scott</user>
>          <password>tiger</password>
>          <hostname>localhost</hostname>
>          <port>1521</port>
>          <timestamp>12345888</timestamp>
>          <class>oracle.jdbc.OracleDriver</class>
>          <url>jdbc:oracle:thin at localhost:1521:orcl:scott:tiger</url>
>          <sid>orcl</sid> =20
>       </connection>
>    </connections>
> </dbpirate>
> 
> And here it is after reading it into JDOM and then directly writing it
> back out to another file without modifying it:
> 
> <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> <!--DBPirate Configuration File-->
> <dbpirate>
>  =20
>   =20
>   <connections>
>    =20
>      =20
>     <connection>
>       =20
>         =20
>       <name>Oracle</name>
>      =20
>         =20
>       <user>cbuser</user>
>      =20
>         =20
>       <password>cbpass</password>
>      =20
>         =20
>       <hostname>localhost</hostname>
>      =20
>         =20
>       <port>1521</port>
>      =20
>         =20
>       <timestamp>345678</timestamp>
>      =20
>         =20
>       <class>org.mysql.jdbc.Driver</class>
>      =20
>         =20
>       <url>jdbc:mysql at localhost:3306:cookbook:cbuser:cbpass</url>
>      =20
>         =20
>       <sid>cookbook</sid>
>        =20
>      =20
>     </connection>
>    =20
>      =20
>     <connection>
>       =20
>         =20
>       <name>MySQL</name>
>      =20
>         =20
>       <user>scott</user>
>      =20
>         =20
>       <password>tiger</password>
>      =20
>         =20
>       <hostname>localhost</hostname>
>      =20
>         =20
>       <port>1521</port>
>      =20
>         =20
>       <timestamp>12345888</timestamp>
>      =20
>         =20
>       <class>oracle.jdbc.OracleDriver</class>
>      =20
>         =20
>       <url>jdbc:oracle:thin at localhost:1521:orcl:scott:tiger</url>
>      =20
>         =20
>       <sid>orcl</sid>
>        =20
>      =20
>     </connection>
>    =20
>   =20
>   </connections>
>  =20
> 
> </dbpirate>
> 
> 
> You can see my dilemma.  It messes everything up when I try to delete a
> portion of the document and then recreate it as needed and then output
> it to a file.  Anyone got any idea why this happens and how to fix it?
> Thanks, Jeremy



More information about the jdom-interest mailing list