mbeckerle commented on code in PR #1357:
URL: https://github.com/apache/daffodil/pull/1357#discussion_r1828033479


##########
daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala:
##########
@@ -2769,41 +2770,52 @@ case class Infoset(i: NodeSeq, parent: TestCase) {
 
 case class DFDLInfoset(di: Node, parent: Infoset) {
 
-  private lazy val infosetNodeSeq = {
-    val testCase: TestCase = parent.parent
-    val loader = testCase.parent.loader
-    val optDataSchema: Option[URI] = {
-      testCase.optSchemaFileURI.orElse(testCase.optEmbeddedSchema.map { 
_.uriForLoading })
-    }
-    val src =
-      (di \ "@type").toString match {
-        case "infoset" | "" => {
-          val rawElem = di.child.filter {
-            _.isInstanceOf[scala.xml.Elem]
-          }.head
-          UnitTestSchemaSource(rawElem, testCase.tcName)
-        }
-        case "file" => {
-          val path = di.text.trim()
-          val maybeURI = parent.parent.parent.findTDMLResource(path)
-          val uri = maybeURI.getOrElse(
-            throw new FileNotFoundException(
-              "TDMLRunner: infoset file '" + path + "' was not found"
-            )
-          )
-          URISchemaSource(uriToDiagnosticFile(uri), uri)
-        }
-        case value => Assert.abort("Unknown value for type attribute on 
dfdlInfoset: " + value)
-      }
+  private lazy val testCase: TestCase = parent.parent
+  private lazy val loader = testCase.parent.loader
+  private val ty: String = {
+    val t = (di \ "@type").text.trim
+    if (t.isEmpty) "infoset" else t
+  }
+
+  private val elemOrStr: Either[Elem, String] = {
+    val (elems, others) = di.child.partition(_.isInstanceOf[scala.xml.Elem])
+    (elems, others.text.trim) match {
+      case (Seq(elem: Elem), "") if (ty == "infoset") => Left(elem)
+      case (Seq(), str) if (ty == "file") => Right(str)
+      case _ =>
+        Assert.usageError(
+          """dfdlInfoset element must contain a single root element or a file 
path (when 'type="file"')."""
+        )
+    }
+  }

Review Comment:
   Agreed. Things in XSD should be designed so that XSD can validate them 
rather than more complex rules being required in code. It's a shame that XSD 
1.1 has not caught on, because it can validate such co-constraints. 
   
   The right thing would have been a different element, e.g, dfdlInfosetFile 
which could only have a file path as its value. 



-- 
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