Nekosan
Nekosan

Reputation: 145

Don't substitute HTML entities with HXT

How do you preserve HTML entities using HXT ? The withSubstHTMLEntities SystemConfig doesn't seem to change anything :

runX $ xshow $ readString [] "<doc><p> &gt; </p></doc>"

and

runX $ xshow $ readString [withSubstHTMLEntities no] "<doc><p> &gt; </p></doc>"

both produce

["</ source=\"\"<doc><p> &gt; </p></doc>\"\" transfer-URI=\"string:\" transfer-Message=\"OK\" transfer-Status=\"200\"><doc><p> > </p></doc><//>"]

I have absolutely no clue as to where to look. I pretty much tried all the other option that I can pass to readDocument or readString

Thanks

Upvotes: 3

Views: 128

Answers (1)

tomferon
tomferon

Reputation: 5001

You can use writeDocumentToString from Text.XML.HXT.Arrow.WriteDocument. The signature is :

writeDocumentToString :: ArrowXml a => SysConfigList -> a XmlTree String

So, for instance,

f :: IO String
f = do
  let arr = readString [] "<doc><p> &lt;tag&gt; </p></doc>" >>> writeDocumentToString []
  results <- runX arr
  return . head $ results

f will return IO "<doc><p> &lt;tag> </p></doc>". (which is good enough to avoid <tag> to be parsed as a tag)

Upvotes: 1

Related Questions