5

我正在尝试解析以下 XML 文档HXT

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Key</key>
    <string>Value</string>
</dict>
</plist>

我不想在这里进行任何验证,因为它需要网络访问。不幸的是,HXT 仍然希望安装hxt-curl/hxt-http包来解析这个简单的文档:

Prelude> :m +Text.XML.HXT.Core
Prelude Text.XML.HXT.Core> runX $ readDocument [withValidate no] "example.xml"

fatal error: HTTP handler not configured,
please install package hxt-curl and use 'withCurl' config option
or install package hxt-http and use 'withHTTP' config option

我不想将hxt-curl/hxt-http包添加到依赖项列表中,因为我真的不需要它们。我无法更改正在解析的文档。移动到另一个 xml 解析库也是不可取的。

有没有办法在不添加不必要的包的情况下使用 HXT 解析示例文档?

4

1 回答 1

6

您还必须声明withSubstDTDEntities no,即

runX $ readDocument [withValidate no, withSubstDTDEntities no] "example.xml"

说明:此配置的默认值为 yes,我猜这就是 hxt 尝试下载 dtd 文件的原因。从文档中

关闭此选项并关闭验证可以加快解析速度,在这种情况下不再需要读取 DTD 文档。

于 2014-04-04T09:21:46.010 回答