axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Jordahl <t...@macromedia.com>
Subject RE: Loss of supplied namespace prefix...
Date Mon, 05 Jan 2004 19:09:11 GMT

This patch sounds reasonable to me.  Chris can you open a bug report with
the patch against the latest CVS source?  That way it won't get lost.

Thanks!

--
Tom Jordahl
Macromedia Server Development

-----Original Message-----
From: Chris McClelland [mailto:prophet36@hotmail.com] 
Sent: Friday, December 26, 2003 11:41 AM
To: axis-dev@ws.apache.org
Subject: Loss of supplied namespace prefix...

Hi,
   I noticed that if one constructs a MessageElement from a
org.w3c.dom.Element, the supplied namespace prefix is lost once the
MessageElement is serialized...

MessageElement me = new
MessageElement(XMLUtils.StringToElement("http://www.foo.com", "foo:Fred",
"..."));
StringWriter writer = new StringWriter();
MessageContext msgContext = MessageContext.getCurrentContext();
SerializationContext serializeContext = new SerializationContextImpl(writer,
msgContext);
serializeContext.setSendDecl(false);
me.outputImpl(serializeContext);
writer.close();
System.out.println("me = " + writer.getBuffer().toString());

..outputs "ns1" instead of "foo" as the prefix for the "http://www.foo.com"
namespace.

I fixed this by downloading "JAR with javax.xml.namespace.QName API Class
Files 1.1" from http://java.sun.com/xml/downloads/jaxrpc.html (which,
crucially, supports the QName(namespaceURI, localPart, prefix) constructor)
and by applying the following patches...

root@dream[6]#diff -u cvs/SerializationContextImpl.java
newcvs/SerializationContextImpl.java
--- cvs/SerializationContextImpl.java   2003-12-26 15:47:45.000000000 +0000
+++ newcvs/SerializationContextImpl.java        2003-12-26
16:03:14.000000000 +0000
@@ -493,7 +493,12 @@
                 }
             }
         } else {
-            prefix = getPrefixForURI(namespaceURI);
+            prefix = qName.getPrefix();
+            if ( prefix != null ) {
+                registerPrefixForURI(prefix, namespaceURI);
+            } else {
+                prefix = getPrefixForURI(namespaceURI);
+            }
         }

         if ((prefix == null) || (prefix.length() == 0))
@@ -1109,9 +1114,15 @@

         String namespaceURI = el.getNamespaceURI();
         String localPart = el.getLocalName();
+        String prefix = el.getPrefix();
         if(namespaceURI == null || namespaceURI.length()==0)
             localPart = el.getNodeName();
-        QName qName = new QName(namespaceURI, localPart);
+        QName qName;
+        if ( prefix != null ) {
+            qName = new QName(namespaceURI, localPart, prefix);
+        } else {
+            qName = new QName(namespaceURI, localPart);
+        }

         startElement(qName, attributes);

root@dream[7]#diff -u cvs/MessageElement.java newcvs/MessageElement.java
--- cvs/MessageElement.java     2003-12-26 15:48:15.000000000 +0000
+++ newcvs/MessageElement.java  2003-12-26 15:54:38.000000000 +0000
@@ -197,6 +197,7 @@
         elementRep = elem;
         namespaceURI = elem.getNamespaceURI();
         name = elem.getLocalName();
+        prefix = elem.getPrefix();
     }

     public MessageElement(Text text)
root@dream[8]#

I have only just started using Axis, and I'm not very familiar with the
code, so please forgive me if the above changes are garbage.

- Chris

Mime
View raw message