[jboss-svn-commits] JBoss Common SVN: r2010 - common-core/trunk/src/main/java/org/jboss/util/xml

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Sep 4 16:17:39 EDT 2006


Author: thomas.diesler at jboss.com
Date: 2006-09-04 16:17:38 -0400 (Mon, 04 Sep 2006)
New Revision: 2010

Modified:
   common-core/trunk/src/main/java/org/jboss/util/xml/DOMWriter.java
Log:
support attr prefixes

Modified: common-core/trunk/src/main/java/org/jboss/util/xml/DOMWriter.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/xml/DOMWriter.java	2006-09-04 14:24:46 UTC (rev 2009)
+++ common-core/trunk/src/main/java/org/jboss/util/xml/DOMWriter.java	2006-09-04 20:17:38 UTC (rev 2010)
@@ -245,27 +245,42 @@
             out.print('<');
             out.print(nodeName);
             
-            String prefix = node.getPrefix();
-            String nsURI = (prefix != null ? getNamespaceURI(prefix, element, rootNode) : null);
+            Map nsMap = new HashMap();
+            String elPrefix = node.getPrefix();
+            if (elPrefix != null)
+            {
+               String nsURI = getNamespaceURI(elPrefix, element, rootNode);
+               nsMap.put(elPrefix, nsURI);
+            }
             
             Attr attrs[] = sortAttributes(node.getAttributes());
             for (int i = 0; i < attrs.length; i++)
             {
                Attr attr = attrs[i];
-               String attrName = attr.getNodeName();
-               String attrValue = normalize(attr.getNodeValue());
+               String atPrefix = attr.getPrefix();
+               String atName = attr.getNodeName();
+               String atValue = normalize(attr.getNodeValue());
                
-               if (prefix != null && attrName.equals("xmlns:" + prefix))
-                  nsURI = attrValue;
+               if (atPrefix != null && atPrefix.equals("xmlns") == false)
+               {
+                  String nsURI = getNamespaceURI(atPrefix, element, rootNode);
+                  nsMap.put(atPrefix, nsURI);
+               }
                
-               out.print(" " + attrName + "='" + attrValue + "'");
+               out.print(" " + atName + "='" + atValue + "'");
             }
             
             // Add missing namespace declaration
-            if (prefix != null && nsURI == null)
+            Iterator itPrefix = nsMap.keySet().iterator();
+            while (itPrefix.hasNext())
             {
-               nsURI = getNamespaceURI(prefix, element, null);
-               out.print(" xmlns:" + prefix + "='" + nsURI + "'");
+               String prefix = (String)itPrefix.next();
+               String nsURI = (String)nsMap.get(prefix);
+               if (nsURI == null)
+               {
+                  nsURI = getNamespaceURI(prefix, element, null);
+                  out.print(" xmlns:" + prefix + "='" + nsURI + "'");
+               }
             }
 
             if (hasChildNodes)
@@ -524,4 +539,4 @@
       }
       return (str.toString());
    }
-}
\ No newline at end of file
+}




More information about the jboss-svn-commits mailing list