jadams-tresys commented on code in PR #1650:
URL: https://github.com/apache/daffodil/pull/1650#discussion_r3214099149


##########
daffodil-core/src/main/scala/org/apache/daffodil/lib/xml/XMLUtils.scala:
##########
@@ -644,34 +653,66 @@ object XMLUtils {
 
   private def removeMixedWhitespace(ns: Node): Node = {
     if (!ns.isInstanceOf[Elem]) return ns
-    val e = ns.asInstanceOf[Elem]
-    val children = e.child
-    val noMixedChildren =
-      if (children.exists(_.isInstanceOf[Elem])) {
-        children
-          .filter {
-            case Text(data) if data.matches("""\s*""") => false
-            case Text(data) =>
-              throw new Exception("Element %s contains mixed data: 
%s".format(e.label, data))
-            case _ => true
-          }
-          .map(removeMixedWhitespace)
-      } else {
-        children.filter {
-          //
-          // So this is a bit strange, but we're dropping nodes that are Empty 
String.
-          //
-          // In XML we cannot tell <foo></foo> where there is a Text("") 
child, from <foo></foo> with Nil children
-          //
-          case Text("") => false // drop empty strings
-          case _ => true
+
+    ns match {
+      // NOTE: this is specifically for the stringAsXml feature as we avoid
+      // making changes to any of its children except removing any surrounding
+      // whitespace, requiring that stringAsXml in the infoset match results 
exactly.
+      case e @ Elem(
+            null,
+            XMLTextInfoset.stringAsXml,
+            Null,
+            NamespaceBinding(null, null | "", _),
+            _*
+          ) => {
+        val (elemChildren, nonElemChildren) = e.child.partition {
+          _.isInstanceOf[Elem]
+        }
+        if (elemChildren.length != 1)
+          throw new Exception("stringAsXml must contain a single child 
element.")

Review Comment:
   Thoughts on changing these and the below generic Exception throws to 
asserts?  Does having it be an exception allow it to be caught or converted 
into a ParseError later on?  Not sure how these sort of failure cases are 
supposed to be handled with the stringAsXML feature.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to