丑陋的xml输出
我正在使用HaXml转换XML文件,它运行得非常好。然而,HaXml生成的输出看起来非常难看,主要是因为它在几乎每个右括号处插入了换行符。 下面是一些生成xml的代码:丑陋的xml输出,xml,haskell,haxml,Xml,Haskell,Haxml,我正在使用HaXml转换XML文件,它运行得非常好。然而,HaXml生成的输出看起来非常难看,主要是因为它在几乎每个右括号处插入了换行符。 下面是一些生成xml的代码: writeFile outPath (show . PP.content . head $ test (docContent (posInNewCxt "" Nothing) (xmlParse "" ""))) test = mkElemAttr "test" [("a", literal "1"), ("b",
writeFile outPath (show . PP.content . head $ test (docContent (posInNewCxt "" Nothing) (xmlParse "" "")))
test =
mkElemAttr "test" [("a", literal "1"), ("b", literal "2")]
[
mkElem "nested" []
]
这是它生成的输出:
<test a="1" b="2"
><nested/></test>
当然,元素越多,情况就越糟
我知道HaXml使用Text.PrettyPrint.HughesPJ进行渲染,但使用不同的
变化不大
那么,有没有办法更改输出?将您对
show
的调用替换为可以获得一些不同的行为:
import Text.XML.HaXml
import Text.XML.HaXml.Util
import Text.XML.HaXml.Posn
import qualified Text.XML.HaXml.Pretty as PP
import Text.PrettyPrint
main = writeFile "/tmp/x.xml" (renderStyle s . PP.content
. head $
test (docContent (posInNewCxt "" Nothing) (xmlParse "" "")))
where
s = style { mode = LeftMode, lineLength = 2 }
test =
mkElemAttr "test" [("a", literal "1"), ("b", literal "2")]
[
mkElem "nested" []
]
尝试不同的开箱即用样式:
默认样式
在这里,您的自定义行为可以编程到
TextDetails
函数中。Mh,我想我必须编写自己的fullRender,或者干脆接受结果。也许我会尝试复制现有的默认样式并删除换行符。
<test a="1" b="2"
><nested/></test>
<test a="1" b="2" ><nested/></test>
<test a="1"
b="2"
><nested/></test>
fullRender
:: Mode -- Rendering mode
-> Int -- Line length
-> Float -- Ribbons per line
-> (TextDetails -> a -> a) -- What to do with text
-> a -- What to do at the end
-> Doc -- The document
-> a -- Result