You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Andrew Vardeman <an...@iastate.edu> on 2003/04/09 16:19:06 UTC

possible bug in DOM2Writer?

***sorry if this is a duplicate message.  I sent it yesterday and it 
doesn't seem to have shown up on the list...***

Hi Axis developers.

Thanks (again) for great, free software.

I think I have noticed a slight incompatibility between Oracle's DOM 
implementation and DOM2Writer's print method.

I am using XMLUtils to dump DOM Elements to strings for an XML log file for 
my service.  When I create a no-namespace Element with Oracle's DOM 
implementation, the namespace and namespace prefix get set to empty 
strings, not null.  Then, when I call 
XMLUtils.ElementToString(anOracleElement), the returned string has a 
renegade xmlns:="", which some XML parsers seem to accept while others 
choke.  I believe changing line 169 in DOM2Writer from:

                 if (elPrefix != null && elNamespaceURI != null)
to
                 if (elPrefix != null && elNamespaceURI != null  && 
elPrefix.length() > 0)

would solve the problem, but I don't know of an easy way to test this, 
knowing nothing about Ant and whatever else I'd need to rebuild my own Axis 
jars.

I've included a small test program I wrote that demonstrates the problem 
I'm having; the code and its output are below.  It uses classes from the 
Oracle XDK, which can be downloaded here:

http://technet.oracle.com/tech/xml/xdk_java/content.html

I'd be thrilled if someone who understands the inner workings of DOM2Writer 
better than me could take a look at this.

Thanks in advance,

Andrew


################################## TEST CODE ##################################

import oracle.xml.parser.v2.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.axis.utils.XMLUtils;

public class OracleDomTesterThing {
     /**
      * @param args the command line arguments
      */
     public static void main(String[] args)
     {
         XMLDocument d = new XMLDocument();
         System.out.println("Created an Oracle XMLDocument d as new 
XMLDocument()");

         Element e = d.createElement("helloThere");
         System.out.println("Used the XMLDocument to create an Element e " +
                            "with d.createElement(\"helloThere\")");

         String prefix = e.getPrefix();
         String namespaceURI = e.getNamespaceURI();
         if(prefix == null)
         {
             System.out.println("e.getPrefix() returns null");
         }
         else
         {
             System.out.println("e.getPrefix() returns a non-null String: "
                                 + '[' + prefix + ']');
         }
         if(namespaceURI == null)
         {
             System.out.println("e.getNamespaceURI() returns null");
         }
         else
         {
             System.out.println("e.getNamespaceURI() returns a non-null 
String: "
                                + '[' + namespaceURI + ']');
         }

         String s = XMLUtils.ElementToString(e);
         System.out.println("Output of XMLUtils.ElementToString(e): " + s);
     }
}

############################### TEST CODE OUTPUT 
###############################

Created an Oracle XMLDocument d as new XMLDocument()
Used the XMLDocument to create an Element e with d.createElement("helloThere")
e.getPrefix() returns a non-null String: []
e.getNamespaceURI() returns a non-null String: []
Output of XMLUtils.ElementToString(e): <helloThere xmlns:=""/>