stevedlawrence commented on code in PR #1650:
URL: https://github.com/apache/daffodil/pull/1650#discussion_r3219045254
##########
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:
I don't think this wants to be an assert since the input could be an
expected infoset in a TDML file. So if user provides invalid XML in the
infoset, instead of an assert we probably want this to be some kind of
exception.
Maybe we want a custom exception (maybe something like
`InvalidInfosetException`?), then users and the TDML runner can handle this
however they want. The TDMLRunner an just convert it to a TDMLException like it
does most things.
--
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]