mbeckerle commented on a change in pull request #458:
URL: https://github.com/apache/incubator-daffodil/pull/458#discussion_r526200312



##########
File path: 
daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
##########
@@ -528,13 +532,39 @@ abstract class TestCase(testCaseXML: NodeSeq, val parent: 
DFDLTestSuite)
     } else rootAttrib
   }
 
-  lazy val rootNamespaceString = {
+  def getRootNamespaceString(schemaArg : Option[Node]) = {
     if (optExpectedOrInputInfoset.isDefined)
       infosetRootNamespaceString
     else if (embeddedSchema.isDefined)
       XMLUtils.EXAMPLE_NAMESPACE.toString
-    else
-      null
+    else if (this.rootNSAttrib != "")
+      rootNSAttrib
+    else {
+      // For some TDML Processors, we have to provide
+      // the root namespace. They don't provide a way to search
+      // for an element when just the name is unambiguous.
+      // So since nothing was provided, we just grab the
+      // target namespace URI (if any) from the primary
+      // schema file. If that turns out to be wrong, then
+      // the test case has to have an explicit rootNS attribute.
+      val schemaNode = schemaArg.getOrElse {
+        val schemaSource = getSuppliedSchema(None)
+        val source = schemaSource.newInputSource()
+        val node = try{
+          scala.xml.XML.load(source)
+        } catch {
+          // any exception while loading then we just use a dummy node.
+          case e:SAXParseException => <dummy/>
+        }
+        node
+      }
+      val tns = (schemaNode \ "@targetNamespace").text
+      val nsURIString = {
+        if (tns != "") tns
+        else null
+      }
+      nsURIString
+    }

Review comment:
       I like the idea of just specifying the root as a QName vs. having added 
rootNS attribute. 
   
   But ..... probably not worth it.
   
   Turns out this only matters for one situation - TDML negative parser test 
cases. All other kinds of test cases have an infoset, and the root element's 
name and namespace can be taken from that (and do not have to be specified at 
all otherwise).  Any negative parser test case using the ibm cross tester would 
fail with being unable to find the root element for lack of a namespace. 
   
   So this will only matter such time as we try to run TDML test suites against 
IBM DFDL including the negative parser tests. 
   
   Turns out there is one such negative parser test case in the vcard DFDL 
schema. That's what I wanted to fix immediately so we could have clean 
regression of the supposed portable DFDL schemas on both Daffodil and IBM DFDL 
working. 
   
   Ultimately we'd like to run daffodil-test against the ibm cross tester 
(ticket DAFFODIL-2028).
   
    In daffodil-test there are many many such negative parser tests. So having 
a heuristic figure out the namespace in most of those will reduce the need to 
add these rootNS attributes to many of these negative parser test cases. 
   




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

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


Reply via email to