[jdom-interest] possible bug with nested namespaces

John Caron caron at unidata.ucar.edu
Mon Aug 20 14:45:18 PDT 2001

When nested elements declare the same namespace, it appears that when the
inner element is done being processed, the namespace on other elements
contained in the outer element is lost.

I tested against jdom b7, and xerces 2.0.0 beta. Some testing with xerces
without jdom appears to handle it correctly.

Example xml:

<test xmlns:xlink="http://www.w3.org/1999/xlink">

<e1 xlink:href="#htn_sst_decloud"/>

<wipeout xmlns:xlink="http://www.w3.org/1999/xlink">

<server type="DODS" ID="this"


<e1 xlink:href="#htn_sst_decloud2"/>  <!-- NOTE xlink namespace -->



package test.jdom;

import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import org.jdom.transform.*;

import java.io.*;
import java.net.*;
import java.util.*;

public class TestNamespace {

  public TestNamespace( String xmlURL) throws MalformedURLException,
IOException {

    System.out.println(" Opening XML "+xmlURL);
    URL u = new URL( xmlURL);

    Document doc = null;
    try {
      SAXBuilder builder = new SAXBuilder( false);
      doc = builder.build( u);
      System.out.println(" SAXBuilder ok");
    } catch (JDOMException e) {
      System.out.println("***SAXBuilder Parsing error= "+ e.getMessage());

    ByteArrayOutputStream os = new ByteArrayOutputStream(10000);
    XMLOutputter fmt = new XMLOutputter("  ", true);
    try {
      fmt.output(doc, os);
    } catch (IOException e) {
      System.out.println("output exception = "+ e.getMessage());


  public static void main(String[] args) {
    try {
    } catch (Exception e) {
      System.out.println("Main exception = \n"+ e.getMessage());

Output is:

 Opening XML http://www.unidata.ucar.edu/projects/THREDDS/xml/testSave.xml
 SAXBuilder ok
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:xlink="http://www.w3.org/1999/xlink">
    <e1 xlink:href="#htn_sst_decloud" />
        <server type="DODS" ID="this"
xlink:href="html://thredds.unidata.ucar.edu:8080/dodsC/" />
    <e1 href="#htn_sst_decloud2" />  <!-- HERES THE PROBLEM - the xlink
namespace removed !! -->

More information about the jdom-interest mailing list