You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by ja...@apache.org on 2022/09/07 16:35:54 UTC

[daffodil] branch main updated: Fix EXI issues and enable schema aware EXI

This is an automated email from the ASF dual-hosted git repository.

jadams pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new 6270f42f6 Fix EXI issues and enable schema aware EXI
6270f42f6 is described below

commit 6270f42f65c295a85baa733503f82c712062700c
Author: Josh Adams <ja...@owlcyberdefense.com>
AuthorDate: Wed Aug 31 20:52:51 2022 -0400

    Fix EXI issues and enable schema aware EXI
    
    We do not want to escape characters before handing them off to the SAX
    ContentHandler. Also, in order for Exificient's library to maintain nil
    elements the SAX_NAMESPACE_PREFIXES_FEATURE flag must be enabled on the
    XMLReader that is passing events to the EXI ContentHandler.
    
    Schema aware EXI infosets can now be enabled using the "-I exisa" flag.
    This has shown significant size reduction compared to non-schema aware
    EXI.  One limitation however is that it may not play well with large
    values of maxOccurs, but maxOccurs="unbounded" is OK. This is a known
    behavior in Exificient and just a limitation to its behavior.
    
    DAFFODIL-1959
---
 .../org/apache/daffodil/CLI/input/input14.exisa    |  1 +
 .../org/apache/daffodil/CLI/input/input18.exisa    |  1 +
 .../apache/daffodil/parsing/TestCLIParsing.scala   | 25 ++++++-
 .../daffodil/performance/TestCLIPerformance.scala  | 42 ++++++++++++
 .../daffodil/unparsing/TestCLIUnparsing.scala      | 22 ++++++
 .../src/main/scala/org/apache/daffodil/Main.scala  | 80 ++++++++++++++++------
 .../apache/daffodil/infoset/InfosetWalker.scala    |  2 +-
 .../daffodil/infoset/SAXInfosetOutputter.scala     |  3 +-
 .../DaffodilParseOutputStreamContentHandler.scala  |  4 +-
 project/Rat.scala                                  |  2 +
 10 files changed, 155 insertions(+), 27 deletions(-)

diff --git a/daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input14.exisa b/daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input14.exisa
new file mode 100644
index 000000000..725317133
--- /dev/null
+++ b/daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input14.exisa
@@ -0,0 +1 @@
+����4::8���0��62�1���f �
\ No newline at end of file
diff --git a/daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input18.exisa b/daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input18.exisa
new file mode 100644
index 000000000..e3165ef03
--- /dev/null
+++ b/daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input18.exisa
@@ -0,0 +1 @@
+�,��4::8���0��62�1����[�
\ No newline at end of file
diff --git a/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala b/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala
index 2da7dd95f..8cd92fc9f 100644
--- a/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala
+++ b/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala
@@ -1308,10 +1308,10 @@ class TestCLIparsing {
     val shell = Util.start("")
 
     try {
-      val cmd = String.format(Util.echoN("Hello") + "| %s parse -I exi -s %s -r e1 | md5sum", Util.binPath, testSchemaFile)
+      val cmd = String.format(Util.echoN("Hello") + "| %s parse -I exi -s %s -r e1 | %s unparse -I exi -s %s -r e1", Util.binPath, testSchemaFile, Util.binPath, testSchemaFile)
 
       shell.sendLine(cmd)
-      shell.expect(contains("937b3f96ee0b5cd1ac9f537cf8ddc580"))
+      shell.expect(contains("Hello"))
 
       Util.expectExitCode(ExitCode.Success, shell)
 
@@ -1322,6 +1322,27 @@ class TestCLIparsing {
     }
   }
 
+  @Test def test_XXX_CLI_Parsing_SimpleParse_exisa(): Unit = {
+
+    val schemaFile = Util.daffodilPath("daffodil-test/src/test/resources/org/apache/daffodil/section00/general/generalSchema.dfdl.xsd")
+    val (testSchemaFile) = if (Util.isWindows) (Util.cmdConvert(schemaFile)) else (schemaFile)
+
+    val shell = Util.start("")
+
+    try {
+      val cmd = String.format(Util.echoN("Hello") + "| %s parse -I exisa -s %s -r e1 | %s unparse -I exisa -s %s -r e1", Util.binPath, testSchemaFile, Util.binPath, testSchemaFile)
+
+      shell.sendLine(cmd)
+      shell.expect(contains("Hello"))
+
+      Util.expectExitCode(ExitCode.Success, shell)
+
+      shell.send("exit\n")
+      shell.expect(eof)
+    } finally {
+      shell.close()
+    }
+  }
   @Test def test_CLI_Error_Return_Codes(): Unit = {
 
     val shell = Util.start("")
diff --git a/daffodil-cli/src/it/scala/org/apache/daffodil/performance/TestCLIPerformance.scala b/daffodil-cli/src/it/scala/org/apache/daffodil/performance/TestCLIPerformance.scala
index 9d78e676b..42437e10d 100644
--- a/daffodil-cli/src/it/scala/org/apache/daffodil/performance/TestCLIPerformance.scala
+++ b/daffodil-cli/src/it/scala/org/apache/daffodil/performance/TestCLIPerformance.scala
@@ -89,6 +89,27 @@ class TestCLIPerformance {
     }
   }
 
+  @Test def test_XXX_CLI_Performance_2_Threads_2_Times_exisa(): Unit = {
+    val schemaFile = Util.daffodilPath("daffodil-test/src/test/resources/org/apache/daffodil/section06/entities/charClassEntities.dfdl.xsd")
+    val inputFile = Util.daffodilPath("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input1.txt")
+    val (testSchemaFile, testInputFile) = if (Util.isWindows) (Util.cmdConvert(schemaFile), Util.cmdConvert(inputFile)) else (schemaFile, inputFile)
+
+    val shell = Util.start("")
+
+    try {
+      val cmd = String.format("%s performance -I exisa -N 2 -t 2 -s %s -r matrix %s", Util.binPath, testSchemaFile, testInputFile)
+      shell.sendLine(cmd)
+      shell.expect(contains("total parse time (sec):"))
+      shell.expect(contains("avg rate (files/sec):"))
+
+      Util.expectExitCode(ExitCode.Success, shell)
+      shell.sendLine("exit")
+      shell.expect(eof())
+    } finally {
+      shell.close()
+    }
+  }
+
   @Test def test_3394_CLI_Performance_3_Threads_20_Times(): Unit = {
     val schemaFile = Util.daffodilPath("daffodil-test/src/test/resources/org/apache/daffodil/section06/entities/charClassEntities.dfdl.xsd")
     val inputFile = Util.daffodilPath("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input1.txt")
@@ -217,6 +238,27 @@ class TestCLIPerformance {
     }
   }
 
+  @Test def test_XXX_CLI_Performance_Unparse_2_Threads_2_Times_exisa(): Unit = {
+    val schemaFile = Util.daffodilPath("daffodil-test/src/test/resources/org/apache/daffodil/section00/general/generalSchema.dfdl.xsd")
+    val inputFile = Util.daffodilPath("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input14.exisa")
+    val (testSchemaFile, testInputFile) = if (Util.isWindows) (Util.cmdConvert(schemaFile), Util.cmdConvert(inputFile)) else (schemaFile, inputFile)
+
+    val shell = Util.start("")
+
+    try {
+      val cmd = String.format("%s performance --unparse -I exisa -N 2 -t 2 -s %s -r e3 %s", Util.binPath, testSchemaFile, testInputFile)
+      shell.sendLine(cmd)
+      shell.expect(contains("total unparse time (sec):"))
+      shell.expect(contains("avg rate (files/sec):"))
+
+      Util.expectExitCode(ExitCode.Success, shell)
+      shell.sendLine("exit")
+      shell.expect(eof())
+    } finally {
+      shell.close()
+    }
+  }
+
   @Test def test_XXX_CLI_Performance_Unparse_2_Threads_2_Times_null(): Unit = {
     val schemaFile = Util.daffodilPath("daffodil-test/src/test/resources/org/apache/daffodil/section00/general/generalSchema.dfdl.xsd")
     val inputFile = Util.daffodilPath("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input14.txt")
diff --git a/daffodil-cli/src/it/scala/org/apache/daffodil/unparsing/TestCLIUnparsing.scala b/daffodil-cli/src/it/scala/org/apache/daffodil/unparsing/TestCLIUnparsing.scala
index d56ee4b86..6e9ebbb55 100644
--- a/daffodil-cli/src/it/scala/org/apache/daffodil/unparsing/TestCLIUnparsing.scala
+++ b/daffodil-cli/src/it/scala/org/apache/daffodil/unparsing/TestCLIUnparsing.scala
@@ -628,6 +628,28 @@ class TestCLIunparsing {
     }
   }
 
+  @Test def test_xxxx_CLI_Unparsing_SimpleUnparse_exisa(): Unit = {
+
+    val schemaFile = Util.daffodilPath("daffodil-test/src/test/resources/org/apache/daffodil/section00/general/generalSchema.dfdl.xsd")
+    val inputFile = Util.daffodilPath("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input18.exisa")
+    val (testSchemaFile, testInputFile) = if (Util.isWindows) (Util.cmdConvert(schemaFile), Util.cmdConvert(inputFile)) else (schemaFile, inputFile)
+
+    val shell = Util.start("")
+
+    try {
+      val cmd = String.format("%s unparse -I exisa -s %s --root e1 %s", Util.binPath, testSchemaFile, testInputFile)
+      shell.sendLine(cmd)
+      shell.expect(contains("Hello"))
+
+      Util.expectExitCode(ExitCode.Success, shell)
+      shell.send("exit\n")
+      shell.expect(eof)
+      shell.close()
+    } finally {
+      shell.close()
+    }
+  }
+
   @Test def test_xxxx_CLI_Unparsing_SimpleUnparse_null(): Unit = {
 
     val schemaFile = Util.daffodilPath("daffodil-test/src/test/resources/org/apache/daffodil/section00/general/generalSchema.dfdl.xsd")
diff --git a/daffodil-cli/src/main/scala/org/apache/daffodil/Main.scala b/daffodil-cli/src/main/scala/org/apache/daffodil/Main.scala
index 08c547998..9ef5c29bd 100644
--- a/daffodil-cli/src/main/scala/org/apache/daffodil/Main.scala
+++ b/daffodil-cli/src/main/scala/org/apache/daffodil/Main.scala
@@ -52,7 +52,8 @@ import org.apache.logging.log4j.core.config.Configurator
 import org.apache.commons.io.IOUtils
 import org.apache.commons.io.output.NullOutputStream
 import com.siemens.ct.exi.core.helpers.DefaultEXIFactory
-import com.siemens.ct.exi.core.FidelityOptions
+import com.siemens.ct.exi.core.EXIFactory
+import com.siemens.ct.exi.grammars.GrammarFactory
 import com.siemens.ct.exi.main.api.sax.EXIResult
 import com.siemens.ct.exi.main.api.sax.EXISource
 import org.apache.daffodil.Main.ExitCode
@@ -114,6 +115,7 @@ import org.apache.daffodil.xml.DaffodilSAXParserFactory
 import org.apache.daffodil.xml.QName
 import org.apache.daffodil.xml.RefQName
 import org.apache.daffodil.xml.XMLUtils
+import org.apache.daffodil.xml.DFDLCatalogResolver
 
 object InfosetType extends Enumeration {
   type Type = Value
@@ -125,6 +127,7 @@ object InfosetType extends Enumeration {
   val W3CDOM = Value("w3cdom")
   val XML = Value("xml")
   val EXI = Value("exi")
+  val EXISA = Value("exisa")
   val NULL = Value("null")
 }
 
@@ -336,8 +339,10 @@ class CLIConf(arguments: Array[String]) extends scallop.ScallopConf(arguments) {
       case _ => Right(Unit)
     }
 
-    validateOpt(infosetType, stream) {
-      case (Some(InfosetType.EXI), Some(true)) => Left("Streaming mode is not currently supported with EXI infosets.")
+    validateOpt(infosetType, stream, schema) {
+      case (Some(InfosetType.EXI), Some(true), _) => Left("Streaming mode is not currently supported with EXI infosets.")
+      case (Some(InfosetType.EXISA), Some(true), _) => Left("Streaming mode is not currently supported with EXI infosets.")
+      case (Some(InfosetType.EXISA), _, None) => Left("A schema must be specified to use schema-aware compression with EXI")
       case _ => Right(Unit)
     }
   }
@@ -378,6 +383,13 @@ class CLIConf(arguments: Array[String]) extends scallop.ScallopConf(arguments) {
       case (Some(_), Some("-")) | (Some(_), None) => Left("Input must not be stdin during interactive debugging")
       case _ => Right(Unit)
     }
+
+    validateOpt(infosetType, stream, schema) {
+      case (Some(InfosetType.EXI), Some(true), _) => Left("Streaming mode is not currently supported with EXI infosets.")
+      case (Some(InfosetType.EXISA), Some(true), _) => Left("Streaming mode is not currently supported with EXI infosets.")
+      case (Some(InfosetType.EXISA), _, None) => Left("A schema must be specified to use schema-aware compression with EXI")
+      case _ => Right(Unit)
+    }
   }
 
   // Save Parser Subcommand Options
@@ -461,6 +473,11 @@ class CLIConf(arguments: Array[String]) extends scallop.ScallopConf(arguments) {
     requireOne(schema, parser) // must have one of --schema or --parser
     conflicts(parser, List(rootNS)) // if --parser is provided, cannot also provide --root
     validateFileIsFile(config) // --config must be a file that exists
+
+    validateOpt(infosetType, schema) {
+      case (Some(InfosetType.EXISA), None) => Left("A schema must be specified to use schema-aware compression with EXI")
+      case _ => Right(Unit)
+    }
   }
 
   // Generate Subcommand Options
@@ -685,7 +702,20 @@ object Main {
   val blobDir = Paths.get(System.getProperty("user.dir"), "daffodil-blobs")
   val blobSuffix = ".bin"
 
-  def getInfosetOutputter(infosetType: InfosetType.Type, os: java.io.OutputStream)
+  def getExiFactoryOpt(infosetType: InfosetType.Type, schemaUriOpt: Option[URI]): Option[EXIFactory] = {
+    if (infosetType == InfosetType.EXI || infosetType == InfosetType.EXISA) {
+      val ef = DefaultEXIFactory.newInstance
+      if (schemaUriOpt.isDefined && infosetType == InfosetType.EXISA) {
+        val gf = GrammarFactory.newInstance
+        val grammar = gf.createGrammars(schemaUriOpt.get.toURL.openStream(), DFDLCatalogResolver.get)
+        ef.setGrammars(grammar)
+      }
+      Some(ef)
+    } else
+      None
+  }
+
+  def getInfosetOutputter(infosetType: InfosetType.Type, os: java.io.OutputStream, exiFactoryOpt: Option[EXIFactory])
   : Either[InfosetOutputter, ContentHandler] = {
     val outputter = infosetType match {
       case InfosetType.XML => Left(new XMLTextInfosetOutputter(os, pretty = true))
@@ -694,10 +724,9 @@ object Main {
       case InfosetType.JDOM => Left(new JDOMInfosetOutputter())
       case InfosetType.W3CDOM => Left(new W3CDOMInfosetOutputter())
       case InfosetType.SAX => Right(new DaffodilParseOutputStreamContentHandler(os, pretty=true))
-      case InfosetType.EXI => {
-        val exiFactory = DefaultEXIFactory.newInstance()
-        exiFactory.getFidelityOptions.setFidelity(FidelityOptions.FEATURE_PREFIX, true)
-        val exiResult = new EXIResult()
+      case InfosetType.EXI | InfosetType.EXISA => {
+        Assert.invariant(exiFactoryOpt.isDefined)
+        val exiResult = new EXIResult(exiFactoryOpt.get)
         exiResult.setOutputStream(os)
         Right(exiResult.getHandler)
       }
@@ -740,7 +769,7 @@ object Main {
    */
   def infosetDataToInputterData(infosetType: InfosetType.Type, data: Either[Array[Byte],InputStream]): AnyRef = {
     infosetType match {
-      case InfosetType.XML | InfosetType.JSON | InfosetType.SAX | InfosetType.EXI => data match {
+      case InfosetType.XML | InfosetType.JSON | InfosetType.SAX | InfosetType.EXI | InfosetType.EXISA => data match {
         case Left(bytes) => bytes
         case Right(is) => is
       }
@@ -827,7 +856,7 @@ object Main {
         val tl = anyRef.asInstanceOf[ThreadLocal[org.w3c.dom.Document]]
         Left(new W3CDOMInfosetInputter(tl.get))
       }
-      case InfosetType.EXI | InfosetType.SAX => {
+      case InfosetType.EXI | InfosetType.EXISA | InfosetType.SAX => {
         val dp = processor
         Right(dp.newContentHandlerInstance(outChannel))
       }
@@ -893,8 +922,11 @@ object Main {
               case Some("-") | None => System.out
               case Some(file) => new FileOutputStream(file)
             }
+
             val infosetType = parseOpts.infosetType.toOption.get
-            val eitherOutputterOrHandler = getInfosetOutputter(infosetType, output)
+            val exiFactoryOpt = getExiFactoryOpt(infosetType, parseOpts.schema.toOption)
+
+            val eitherOutputterOrHandler = getInfosetOutputter(infosetType, output, exiFactoryOpt)
 
             var lastParseBitPosition = 0L
             var keepParsing = true
@@ -1046,6 +1078,7 @@ object Main {
             }
 
             val infosetType = performanceOpts.infosetType.toOption.get
+            val exiFactoryOpt = getExiFactoryOpt(infosetType, performanceOpts.schema.toOption)
 
             val dataSeq: Seq[Either[AnyRef, Array[Byte]]] = files.map { filePath =>
               // For performance testing, we want everything in memory so as to
@@ -1104,12 +1137,12 @@ object Main {
                               case bytes: Array[Byte] => new ByteArrayInputStream(bytes)
                               case is: InputStream => is
                             }
-                            unparseWithSAX(is, contentHandler, infosetType)
+                            unparseWithSAX(is, contentHandler, infosetType, exiFactoryOpt)
                         }
                       })
                       case Right(data) => Timer.getTimeResult({
                         val input = InputSourceDataInputStream(data)
-                        val eitherOutputterOrHandlerForParse = getInfosetOutputter(infosetType, nullOutputStreamForParse)
+                        val eitherOutputterOrHandlerForParse = getInfosetOutputter(infosetType, nullOutputStreamForParse, exiFactoryOpt)
                         eitherOutputterOrHandlerForParse match {
                           case Left(outputter) => processor.parse(input, outputter)
                           case Right(saxContentHandler) =>
@@ -1222,9 +1255,10 @@ object Main {
                   Right(is)
                 }
 
-              val inputterData = infosetDataToInputterData(unparseOpts.infosetType.toOption.get, eitherBytesOrStream)
-              val inputterOrContentHandler = getInfosetInputter(unparseOpts.infosetType.toOption
-                .get, inputterData, processor, outChannel)
+              val infosetType = unparseOpts.infosetType.toOption.get
+              val exiFactoryOpt = getExiFactoryOpt(infosetType, unparseOpts.schema.toOption)
+              val inputterData = infosetDataToInputterData(infosetType, eitherBytesOrStream)
+              val inputterOrContentHandler = getInfosetInputter(infosetType, inputterData, processor, outChannel)
               val unparseResult = inputterOrContentHandler match {
                 case Left(inputter) =>
                   Timer.getResult("unparsing", processor.unparse(inputter, outChannel))
@@ -1233,7 +1267,7 @@ object Main {
                     case bytes: Array[Byte] => new ByteArrayInputStream(bytes)
                     case is: InputStream => is
                   }
-                  Timer.getResult("unparsing", unparseWithSAX(is, contentHandler, unparseOpts.infosetType.toOption.get))
+                  Timer.getResult("unparsing", unparseWithSAX(is, contentHandler, infosetType, exiFactoryOpt))
               }
 
               displayDiagnostics(unparseResult)
@@ -1432,10 +1466,12 @@ object Main {
   private def unparseWithSAX(
     is: InputStream,
     contentHandler: DFDL.DaffodilUnparseContentHandler,
-    infosetType: InfosetType.Type): UnparseResult = {
+    infosetType: InfosetType.Type,
+    exiFactoryOpt: Option[EXIFactory]): UnparseResult = {
     val xmlReader = infosetType match {
-      case InfosetType.EXI => {
-        val exiSource = new EXISource()
+      case InfosetType.EXI | InfosetType.EXISA => {
+        Assert.invariant(exiFactoryOpt.isDefined)
+        val exiSource = new EXISource(exiFactoryOpt.get)
         exiSource.getXMLReader
       }
       case _ => DaffodilSAXParserFactory().newSAXParser.getXMLReader
@@ -1458,9 +1494,11 @@ object Main {
     data: InputSourceDataInputStream,
     saxContentHandler: ContentHandler): ParseResult = {
     val saxXmlRdr = processor.newXMLReaderInstance
-    saxXmlRdr.setContentHandler(saxContentHandler)
+    // SAX_NAMESPACE_PREFIXES_FEATURE is needed to preserve nil attributes with EXI
+    saxXmlRdr.setFeature(XMLUtils.SAX_NAMESPACE_PREFIXES_FEATURE, true)
     saxXmlRdr.setProperty(XMLUtils.DAFFODIL_SAX_URN_BLOBDIRECTORY, blobDir)
     saxXmlRdr.setProperty(XMLUtils.DAFFODIL_SAX_URN_BLOBSUFFIX, blobSuffix)
+    saxXmlRdr.setContentHandler(saxContentHandler)
     saxXmlRdr.parse(data)
     val pr = saxXmlRdr.getProperty(XMLUtils.DAFFODIL_SAX_URN_PARSERESULT).asInstanceOf[ParseResult]
     pr
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/infoset/InfosetWalker.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/infoset/InfosetWalker.scala
index 16f85526c..7a90d2c5e 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/infoset/InfosetWalker.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/infoset/InfosetWalker.scala
@@ -98,7 +98,7 @@ object InfosetWalker {
  * The purpose of this class is to walk Daffodil's internal infoset
  * representation (i.e. DINodes), starting at a specified DINode, and call the
  * appropriate functions on the InfosetOutputter. The InfosetOutputter provided
- * to this class determines how the internal infoset is projectted to the user
+ * to this class determines how the internal infoset is projected to the user
  * (e.g. XML, json, SAX events).
  *
  * Calling the walk() method causes the InfosetWalker to begin this process. At
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/infoset/SAXInfosetOutputter.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/infoset/SAXInfosetOutputter.scala
index 808f339e1..65a584b86 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/infoset/SAXInfosetOutputter.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/infoset/SAXInfosetOutputter.scala
@@ -63,8 +63,7 @@ class SAXInfosetOutputter(xmlReader: DFDL.DaffodilParseXMLReader,
       if (diSimple.hasValue) {
         val text =
           if (diSimple.erd.optPrimType.get.isInstanceOf[NodeInfo.String.Kind]) {
-            val s = remapped(diSimple.dataValueAsString)
-            scala.xml.Utility.escape(s)
+            remapped(diSimple.dataValueAsString)
           } else {
             diSimple.dataValueAsString
           }
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DaffodilParseOutputStreamContentHandler.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DaffodilParseOutputStreamContentHandler.scala
index 0f7a0b4e4..9e5d9a905 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DaffodilParseOutputStreamContentHandler.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DaffodilParseOutputStreamContentHandler.scala
@@ -290,7 +290,9 @@ class DaffodilParseOutputStreamContentHandler(out: OutputStream, pretty: Boolean
   }
 
   override def characters(ch: Array[Char], start: Int, length: Int): Unit = {
-    writer.write(ch, start, length)
+    val str = new String(ch, start, length)
+    val escaped = scala.xml.Utility.escape(str)
+    writer.write(escaped, 0, escaped.length)
   }
 
   override def ignorableWhitespace(ch: Array[Char], start: Int, length: Int): Unit = {
diff --git a/project/Rat.scala b/project/Rat.scala
index f5d522feb..763eea4a7 100644
--- a/project/Rat.scala
+++ b/project/Rat.scala
@@ -71,11 +71,13 @@ object Rat {
     file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input13.txt"),
     file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input14.txt"),
     file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input14.exi"),
+    file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input14.exisa"),
     file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input15.txt"),
     file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input16.txt"),
     file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input18.json"),
     file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input18.txt"),
     file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input18.exi"),
+    file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input18.exisa"),
     file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/input19.txt"),
     file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/inputBig1M.txt"),
     file("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/input/prefix.txt"),