[jdom-interest] Beta8 DOMBuilder issue

Peter Coppens Peter.Coppens at datadirect-technologies.com
Tue Apr 2 07:43:29 PST 2002


Using the following input XML document

===============
<?xml version="1.0" encoding="UTF-8" ?>
<test xmlns:ns1="http://www.abc.com/ns1" xmlns:ns2="http://www.abc.com/ns2">
  <el1>
    <el2 ns1:at1='at1' ns2:at2='at2'/>
  </el1>
</test>
===============

And the following test program

===============
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.*;


public class tjdom
  {
  static void main ( String argv[] )
    {
    try
      {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance ();
      // Document builder factory properties
      dbf.setNamespaceAware ( true );
      dbf.setValidating ( false );
      // Create document builder
      DocumentBuilder db = dbf.newDocumentBuilder ();
      // Parse document
      Document doc = db.parse ( new org.xml.sax.InputSource ( new
java.io.FileReader ( argv[0] ) ) );
      // Create JDOM
      org.jdom.input.DOMBuilder builder = new org.jdom.input.DOMBuilder();
      org.jdom.Document jdoc = builder.build ( doc );
      // Output JDOM
      org.jdom.output.XMLOutputter xmlOutputter = new
org.jdom.output.XMLOutputter ( "  ", true );
      xmlOutputter.output( jdoc, System.out );
      }
    catch ( Exception e)
      {
      e.printStackTrace ();
      }
    }
  }
===============

I get, using JDOM beta7

===============
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:ns1="http://www.abc.com/ns1" xmlns:ns2="http://www.abc.com/ns2">
  
  <el1>
    
    <el2 ns1:at1="at1" ns2:at2="at2" />
    
  
  </el1>
  

</test>
===============

and using JDOM beta8

===============
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:ns1="http://www.abc.com/ns1" xmlns:ns2="http://www.abc.com/ns2">
  <el1>
    <el2 at1="at1" at2="at2" />
  </el1>
</test>
===============

For some reason, the namespaces got lost. Anybody any suggestions on what I
am doing wrong.

Thanks.

Peter



More information about the jdom-interest mailing list