dsj8000 2015-01-23 10:36
浏览 99
已采纳

如何强制Go的标准xml解析器读取DTD实体

I'm using go's encoding/xml package to parse an XML file. When parsing a file, here's the error I get :

XML syntax error on line 16: invalid character entity ü

But the xml file references a dtd :

<!DOCTYPE dblp SYSTEM "dblp.dtd">

And that dtd itself contains the definition of that entity :

    <!ENTITY uuml    "&#252;" ><!-- small u, dieresis or umlaut mark -->

Is there a way to force Go's xml parser to parse DTDs, did I miss something somewhere or am I doomed to use a third-party xml parser ?

  • 写回答

1条回答 默认 最新

  • douniuta4783 2015-01-23 10:55
    关注

    Probably not the answer you would like to hear...

    You could use the Entity-field of http://golang.org/pkg/encoding/xml/#Decoder. Unfortunately I do not know of an automatic way to generate such entity maps from a dtd. But this should be straightforward to extract from the dtd. If the dtd doesn't change this might be a nice task for go generate.

    If the list if entities is fixed (and small enough) I would hardcode the entity map.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000