Parse invalid/malformed/incomplete XML

213 views
Skip to first unread message

Vladimir Mihailenco

unread,
May 22, 2013, 4:17:00 AM5/22/13
to golan...@googlegroups.com
Hi,

I have a huge amount of malformed XML that was previously accepted and parsed by Ruby. Now I have to reparse it using Go. What are you using to parse invalid/malformed/incomplete XML?

Most popular errors I see are:
- <a><b></b> - missing tag
- <a><b></b - truncated XML
- <foo-bar></foo_bar> - miss-spelled closing tag

Thanks.

Ernest Micklei

unread,
May 23, 2013, 9:21:03 AM5/23/13
to golan...@googlegroups.com
It is possible to pre-process them using a Tidy (like) program ?  (http://tidy.sourceforge.net/)

^ Ernest

Andy Balholm

unread,
Jun 3, 2013, 12:28:51 PM6/3/13
to golan...@googlegroups.com
You could try the HTML parser.

Gustavo Niemeyer

unread,
Jun 3, 2013, 12:45:54 PM6/3/13
to Vladimir Mihailenco, golan...@googlegroups.com
On Wed, May 22, 2013 at 5:17 AM, Vladimir Mihailenco
<vladimi...@gmail.com> wrote:
> I have a huge amount of malformed XML that was previously accepted and
> parsed by Ruby. Now I have to reparse it using Go. What are you using to
> parse invalid/malformed/incomplete XML?
>
> Most popular errors I see are:
> - <a><b></b> - missing tag

encoding/xml can handle these. See the docs for Decoder:

http://golang.org/pkg/encoding/xml#Decoder

> - <a><b></b - truncated XML
> - <foo-bar></foo_bar> - miss-spelled closing tag

These feel wildly broken. The encoding/xml package could possibly
ignore the bogus end tag, but it'd be pretty hard to get sensible
behavior out of it.


gustavo @ http://niemeyer.net
Reply all
Reply to author
Forward
0 new messages