jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/dom3/DOM3TreeWalker.java
changeset 42805 857b5e6eef37
parent 33351 6e177c9004fd
child 43845 93896d0f44f3
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/dom3/DOM3TreeWalker.java	Fri Dec 16 08:18:05 2016 +0000
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/dom3/DOM3TreeWalker.java	Mon Dec 19 11:13:32 2016 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -368,8 +368,6 @@
     private final void dispatachChars(Node node)
         throws org.xml.sax.SAXException {
         if (fSerializer != null) {
-            this.fSerializer.characters(node);
-        } else {
             String data = ((Text) node).getData();
             this.fSerializer.characters(data.toCharArray(), 0, data.length());
         }
@@ -1066,7 +1064,9 @@
                 // should we pass entity reference nodes to the filter???
             }
 
-            if (fLexicalHandler != null) {
+            // if "entities" is true, or EntityReference node has no children,
+            // it will be serialized as the form "&entityName;" in the output.
+            if (fLexicalHandler != null && ((fFeatures & ENTITIES) != 0 || !node.hasChildNodes())) {
 
                 // startEntity outputs only Text but not Element, Attr, Comment
                 // and PI child nodes.  It does so by setting the m_inEntityRef