[jboss-svn-commits] JBoss Common SVN: r2011 - common-old/branches/Branch_1_0/src/main/org/jboss/util/xml

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Sep 4 16:24:50 EDT 2006


Author: thomas.diesler at jboss.com
Date: 2006-09-04 16:24:48 -0400 (Mon, 04 Sep 2006)
New Revision: 2011

Modified:
   common-old/branches/Branch_1_0/src/main/org/jboss/util/xml/DOMWriter.java
Log:
support attr prefixes

Modified: common-old/branches/Branch_1_0/src/main/org/jboss/util/xml/DOMWriter.java
===================================================================
--- common-old/branches/Branch_1_0/src/main/org/jboss/util/xml/DOMWriter.java	2006-09-04 20:17:38 UTC (rev 2010)
+++ common-old/branches/Branch_1_0/src/main/org/jboss/util/xml/DOMWriter.java	2006-09-04 20:24:48 UTC (rev 2011)
@@ -244,27 +244,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)
@@ -523,4 +538,4 @@
       }
       return (str.toString());
    }
-}
\ No newline at end of file
+}




More information about the jboss-svn-commits mailing list