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.

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改