diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@
 
 ```bash
 cabal update
-cabal install --overwrite-policy=always phino-0.0.0.64
+cabal install --overwrite-policy=always phino-0.0.0.65
 phino --version
 ```
 
diff --git a/phino.cabal b/phino.cabal
--- a/phino.cabal
+++ b/phino.cabal
@@ -1,6 +1,6 @@
 cabal-version: 3.0
 name: phino
-version: 0.0.0.65
+version: 0.0.0.66
 license: MIT
 synopsis: Command-Line Manipulator of 𝜑-Calculus Expressions
 description: Please see the README on GitHub at <https://github.com/objectionary/phino#readme>
@@ -83,20 +83,20 @@
     base >=4.18.3.0 && <5,
     binary-ieee754 >=0.1.0 && <0.2,
     bytestring >=0.11.4 && <0.13,
-    containers >=0.6.5 && <0.8,
+    containers >=0.6.5 && <0.9,
     directory >=1.3.7 && <1.4,
     file-embed >=0.0.15 && <0.0.17,
-    filepath >=1.4.200 && <1.5,
+    filepath >=1.4.200 && <1.6,
     megaparsec >=9.5 && <9.8,
     optparse-applicative >=0.18 && <0.20,
     random >=1.2 && <1.3,
     regex-pcre-builtin >=0.95.2 && <0.96,
     scientific >=0.3.7 && <0.4,
     text >=2.0.2 && <2.2,
-    time >=1.12 && <1.15,
+    time >=1.12 && <1.16,
     utf8-string >=1.0.2 && <1.1,
     vector >=0.13.0 && <0.14,
-    xml-conduit >=1.9 && <1.10,
+    xml-conduit >=1.9 && <1.11,
     yaml >=0.11.8 && <0.12,
 
   default-language: Haskell2010
@@ -155,9 +155,9 @@
     aeson >=2.2.3 && <2.3,
     base >=4.18.3.0 && <5,
     bytestring >=0.11.4 && <0.13,
-    containers >=0.6.5 && <0.8,
+    containers >=0.6.5 && <0.9,
     directory >=1.3.7 && <1.4,
-    filepath >=1.4.200 && <1.5,
+    filepath >=1.4.200 && <1.6,
     hspec >=2.11.0 && <2.12,
     hspec-core >=2.11.0 && <2.12,
     megaparsec >=9.5 && <9.8,
@@ -166,8 +166,8 @@
     process >=1.6.17 && <1.7,
     silently >=1.2.5 && <1.3,
     text >=2.0.2 && <2.2,
-    time >=1.12 && <1.15,
-    xml-conduit >=1.9 && <1.10,
+    time >=1.12 && <1.16,
+    xml-conduit >=1.9 && <1.11,
     yaml >=0.11.8 && <0.12,
 
   build-tool-depends:
diff --git a/src/CLI/Runners.hs b/src/CLI/Runners.hs
--- a/src/CLI/Runners.hs
+++ b/src/CLI/Runners.hs
@@ -43,7 +43,10 @@
   input <- readInput _inputFile
   rules <- getRules _normalize _shuffle _rules
   program <- parseProgram input _inputFormat
-  let listing = if null rules then const input else (\prog -> P.printProgram' prog (_sugarType, UNICODE, _flat, _margin))
+  let listing = case (rules, _inputFormat, _outputFormat) of
+        ([], XMIR, XMIR) -> (\_ -> escapeXML input)
+        ([], _, _) -> const input
+        (_, _, _) -> (\prog -> P.printProgram' prog (_sugarType, UNICODE, _flat, _margin))
       xmirCtx = XmirContext _omitListing _omitComments listing
       printCtx = printProgCtx xmirCtx foc
       canonize = if _canonize then C.canonize else id
diff --git a/src/XMIR.hs b/src/XMIR.hs
--- a/src/XMIR.hs
+++ b/src/XMIR.hs
@@ -14,6 +14,7 @@
   , parseXMIRThrows
   , xmirToPhi
   , defaultXmirContext
+  , escapeXML
   , XmirContext (XmirContext)
   )
 where
@@ -253,6 +254,17 @@
           nanos = floor (fractional * 1_000_000_000) :: Int
        in base ++ "." ++ printf "%09d" nanos ++ "Z"
 programToXMIR prog _ = throwIO (UnsupportedProgram prog)
+
+escapeXML :: String -> String
+escapeXML = concatMap escapeChar
+  where
+    escapeChar :: Char -> String
+    escapeChar '&' = "&amp;"
+    escapeChar '<' = "&lt;"
+    escapeChar '>' = "&gt;"
+    escapeChar '"' = "&quot;"
+    escapeChar '\'' = "&apos;"
+    escapeChar ch = [ch]
 
 -- Add indentation (2 spaces per level).
 indent :: Int -> TB.Builder
diff --git a/test/CLISpec.hs b/test/CLISpec.hs
--- a/test/CLISpec.hs
+++ b/test/CLISpec.hs
@@ -411,6 +411,21 @@
           ["rewrite", "--input=xmir", "--sweet"]
           ["{⟦ app ↦ ⟦ x ↦ Φ.number ⟧ ⟧}"]
 
+    it "rewrites and prints with XMIR as input and output" $
+      withStdin
+        ( intercalate
+            ""
+            [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+            , "<object><o name=\"app\"><o name=\"x\" base=\"Φ.number\"/></o></object>"
+            ]
+        )
+        ( testCLISucceeded
+            ["rewrite", "--input=xmir", "--output=xmir", "--sweet"]
+            [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+            , "<listing>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;object&gt;&lt;o name=&quot;app&quot;&gt;&lt;o name=&quot;x&quot; base=&quot;Φ.number&quot;/&gt;&lt;/o&gt;&lt;/object&gt;</listing>"
+            ]
+        )
+
     it "rewrites as XMIR with omit-listing flag" $
       withStdin "Q -> [[ x -> Q.y ]]" $
         testCLISucceeded
