abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r640071 - /incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
Date Sat, 22 Mar 2008 20:21:50 GMT
Author: jmsnell
Date: Sat Mar 22 13:21:49 2008
New Revision: 640071

URL: http://svn.apache.org/viewvc?rev=640071&view=rev
Log:
Declare namespaces conditionally

Modified:
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java?rev=640071&r1=640070&r2=640071&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
Sat Mar 22 13:21:49 2008
@@ -25,6 +25,7 @@
 import java.util.Map;
 import java.util.Stack;
 
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
@@ -150,6 +151,12 @@
     }
   }
   
+  private boolean needToWriteNamespace(String prefix, String namespace) {
+    NamespaceContext nc = writer.getNamespaceContext();
+      String uri = nc.getNamespaceURI(prefix);
+      return uri != null ? !uri.equals(namespace) : true;
+  }
+  
   public StreamWriter startElement(
     String name, 
     String namespace, 
@@ -162,13 +169,15 @@
           prefix,
           name,
           namespace);
-        writeNamespace(prefix,namespace,false);
+        if (needToWriteNamespace(prefix,namespace))
+          writeNamespace(prefix,namespace,false);
       } else if (namespace != null) {
         writer.writeStartElement(
           "",
           name, 
           namespace);
-        writer.writeDefaultNamespace(namespace);
+        if (needToWriteNamespace(prefix,namespace))
+          writer.writeDefaultNamespace(namespace);
       } else {
         writer.writeStartElement("",name,"");
         writer.writeDefaultNamespace("");



Mime
View raw message