[Yanel-commits] rev 23983 - public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization

simon at wyona.com simon at wyona.com
Tue Apr 24 09:47:08 CEST 2007


Author: simon
Date: 2007-04-24 09:46:52 +0200 (Tue, 24 Apr 2007)
New Revision: 23983

Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization/HTMLSerializer.java
Log:
fix for the htmlserializer bug #5309:
- add <div> to non-collapsable elements
- add html namespace to root element
- remove all other namespace attributes
thanks to josias!

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization/HTMLSerializer.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization/HTMLSerializer.java	2007-04-23 21:27:14 UTC (rev 23982)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/serialization/HTMLSerializer.java	2007-04-24 07:46:52 UTC (rev 23983)
@@ -21,8 +21,9 @@
     private EntityResolver entityResolver;
     private String pendingElement = null;
     private boolean doIndent;
+    private boolean visitedRootElement = false;
     
-    private String[] nonCollapsableElements = { "textarea", "script", "style" };
+    private String[] nonCollapsableElements = { "textarea", "script", "style", "div" };
 
     public HTMLSerializer() {
     }
@@ -64,18 +65,20 @@
         handlePendingElement();
         String eName = ("".equals(localName)) ? qName : localName;
         
-        if (localName.equals("html")) {
-            print("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
-            return;
-        }
         StringBuffer element = new StringBuffer();
         element.append("<" + eName);
+        
+        // add xhtml namespace to the root element:
+        if (!this.visitedRootElement) {
+            element.append(" xmlns=\"http://www.w3.org/1999/xhtml\"");
+            this.visitedRootElement = true;
+        }
         for(int i = 0; i < attrs.getLength(); i++) {
             String aLocalName = attrs.getLocalName(i);
             String aQName = attrs.getQName(i);
             String aName = ("".equals(aLocalName)) ? aQName : aLocalName;
-            String aURI = attrs.getURI(i);
-            if (!aName.equals("xmlns") || !aURI.equals("http://www.w3.org/2000/xmlns/")) {
+            // don't copy namespace attributes
+            if (!(aLocalName.startsWith("xmlns") || aQName.startsWith("xmlns"))) {
                 String aValue = replaceEntities(attrs.getValue(i));
                 element.append(" " + aName + "=\"" + aValue + "\"");
             }




More information about the Yanel-commits mailing list