[jdom-commits] CVS update: jdom/src/java/org/jdom/output

jhunter at cvs.jdom.org jhunter at cvs.jdom.org
Thu Dec 14 20:46:59 PST 2000


Date:	Friday December 15, 2000 @ 4:46
Author:	jhunter

Update of /home/cvspublic/jdom/src/java/org/jdom/output
In directory www.nmemonix.com:/tmp/cvs-serv5878

Modified Files:
	XMLOutputter.java 
Log Message:
Fixed bug where an element not in any namespace will still inherit 
the default namespace from an ancestor.

In other words,

<foo xmlns="http://bar">
  <kid xmlns=""/>
</foo>

Would be read and stored correctly but output incorrectly as:

<foo xmlns="http://bar">
  <kid/>
</foo>

It now outputs correctly again.

Test programs are below:

import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;

public class NoNamespace {

  public static void main(String[] args) throws Exception {

    XMLOutputter outputter = new XMLOutputter("  ", true);
    outputter.setTrimText(true);

    Document doc = new Document(
      new Element("parent"));

    outputter.output(doc, System.out);
    System.out.println(doc.getRootElement());
    Iterator itr = doc.getRootElement().getChildren().iterator();
    while (itr.hasNext()) {
      Element next = (Element) itr.next();
      System.out.println("  " + next);
      Iterator itr2 = next.getChildren().iterator();
      while (itr2.hasNext()) {
        System.out.println("    " + itr2.next());
      }
    }
  }
}

import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;

public class NoNamespaceKid {

  public static void main(String[] args) throws Exception {

    XMLOutputter outputter = new XMLOutputter("  ", true);
    outputter.setTrimText(true);

    Namespace ns = Namespace.getNamespace("", "http://uri");
    Document doc = new Document(
      new Element("parent", ns)
      .addContent(new Element("kid")));

    outputter.output(doc, System.out);
    System.out.println(doc.getRootElement());
    Iterator itr = doc.getRootElement().getChildren().iterator();
    while (itr.hasNext()) {
      Element next = (Element) itr.next();
      System.out.println("  " + next);
      Iterator itr2 = next.getChildren().iterator();
      while (itr2.hasNext()) {
        System.out.println("    " + itr2.next());
      }
    }
  }
}

-jh-

===================================================================
File: XMLOutputter.java	Status: Up-to-date

   Working revision:	1.33	Fri Dec 15 04:46:58 2000
   Repository revision:	1.33	/home/cvspublic/jdom/src/java/org/jdom/output/XMLOutputter.java,v

   Existing Tags:
	start                    	(revision: 1.1.1.1)
	jdom                     	(branch: 1.1.1)




More information about the jdom-commits mailing list