XSD Validation

359 views
Skip to first unread message

krolaw

unread,
Feb 19, 2015, 4:35:25 PM2/19/15
to golan...@googlegroups.com
Hi,

I'm looking for a way to allow a go web service to check input XML against a provided XSD schema, before forwarding it on to another service.

Does anyone have some example code that validates xml from a provided schema?

I thought the easiest way forward would be to find a package that wraps libxml2.  However, either the wrappers I have looked at are incomplete, or I'm ignorant on how to call the various functions to schema validate xml.

Suggestions gratefully appreciated.

Thanks.

Feyyaz Esatoglu

unread,
Feb 19, 2015, 6:41:10 PM2/19/15
to golan...@googlegroups.com
https://github.com/metaleap/go-xsd it looks like what you need

"With this, you could probably write an XML validator, or otherwise utilize or further process the loaded XSD --- but the main use-case here was:"

krolaw

unread,
Feb 19, 2015, 9:14:53 PM2/19/15
to golan...@googlegroups.com
Unfortunately, the XSD may be supplied as user data.  Having it compiled in isn't desirable.  It's pretty cool, but not applicable for this purpose.

Thanks.

krolaw

unread,
Feb 26, 2015, 3:39:51 AM2/26/15
to golan...@googlegroups.com
Hi,

I didn't have any luck finding a Go XML Schema validation solution, so I thought I would try my hand with CGO and write a libxml2 wrapper myself.  Whilst I can validate, I can't extract the error messages on failure.  I was wondering if someone who is familiar with CGO would have a look at my coding attempts and offer some guidance (and any other feedback deemed appropriate).

The project is at:

Many thanks.

Konstantin Khomoutov

unread,
Feb 26, 2015, 4:47:12 AM2/26/15
to krolaw, golan...@googlegroups.com
On Thu, 26 Feb 2015 00:39:51 -0800 (PST)
krolaw <kro...@gmail.com> wrote:

> Hi,
>
> I didn't have any luck finding a Go XML Schema validation solution,
> so I thought I would try my hand with CGO and write a libxml2 wrapper
> myself. Whilst I can validate, I can't extract the error messages on
> failure. I was wondering if someone who is familiar with CGO would
> have a look at my coding attempts and offer some guidance (and any
> other feedback deemed appropriate).
>
> The project is at:
> https://github.com/krolaw/xsd

Sorry, have no time to look at your code, but did you look at already
available libxml2 bindings [1, 2]? They might have implemented this
aspect already.

By the way, goxml looks particularly comprehensive. May be it worth
getting in touch with the authors of these packages and discuss
contributing your code into one/both of them? I mean, too much
fragmentation is not very good, and IMO it would be better to have a
single package exposing most of libxml2 than three packages each
exposing just some bits of it.

P.S.
I've found these packages by searching on [3].

1. https://github.com/martende/goxml
2. https://github.com/teejae/go-libxml
3. http://godoc.org

Richard Warburton

unread,
Feb 26, 2015, 5:17:58 AM2/26/15
to Konstantin Khomoutov, golang-nuts
Hi,

Thanks for your email.  I have searched previously myself.  The two links provided don't do schema validation.

I have found one author who was interested in having such functionality contributed.  However, all the wrapper libs I have looked at just expose the C functions, and don't feel like go libraries (i.e. no second return value for errors).  Because I'm going in a different direction, my code probably won't fit well with existing libraries.  But I'll ask anyway.

In any case, I don't have much to show unless I can expose validation errors.

Cheers.
Reply all
Reply to author
Forward
0 new messages